Skip to content

Deprecate explicit use of event_loop fixture in async tests #638

@seifertm

Description

@seifertm

There are currently two options to retrieve the asyncio event loop inside an async test. One is to request the event_loop fixture in the test arguments:

async def test_requests_event_loop(event_loop):
    ...

The other way is to retrieve the event loop via the asyncio module:

async def test_gets_running_loop():
    event_loop = asyncio.get_running_loop()

The latter is more portable between pytest-asyncio and other asyncio-capable test runners, e.g. unittest. I don't see any benefit of option 1.

Therefore, I propose to emit a warning when the user explicitly requests the event_loop fixture in an async test function. Note that requesting the event_loop fixture in a synchronous function should still be supported.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions