[Python] How to parametrize all async tests?

Discussão em 'Python' iniciado por Stack, Julho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have many test functions, sync and async.

    I'm using pytest-asyncio in the "auto" mode, so it detects all async tests and I don't have to mark them as such.

    My problem is that I want to parametrize all my async tests. I want to run them twice, using two different task factories.

    As a quick fix I'm using a fixture with the "autouse" parameter. Regarding the asyncio task factories it works well. But it uselessly runs twice also the sync tests and that wastes time.

    @pytest.fixture(scope="module", params=[False, True], autouse=True)
    async def fixture_task_factories(request):
    factory = asyncio.eager_task_factory if request.param else None
    asyncio.get_running_loop().set_task_factory(factory)


    How can I apply such fixture only to async tests, i.e. tests that the pytest-asyncio is responsible for?

    Continue reading...

Compartilhe esta Página