Skip to content

Allow the asyncio_event_loop mark to be applied to test coroutines #646

Closed as not planned
@seifertm

Description

@seifertm

#620 introduced the asyncio_event_loop mark, which provides a class-scoped or module-scoped event loop when a class or module is marked, respectively. The mark optionally allows specifying one or more event loop policies used to create the scoped event loop. This functionality is intended to supersede the practice of overriding the event_loop fixture.

#631 deprecated event_loop fixture overrides, but there's no replacement for custom loop policies with function-scoped loops, for example:

@pytest.fixture(
    params=[
        DefaultEventLoopPolicy(),
        CustomEventLoopPolicy(),
    ]
)
def event_loop(request):
    policy = request.param
    loop = policy.new_event_loop()
    yield loop
    
async def test_should_run_twice():
    pass

Therefore, the asyncio_event_loop mark should be adjusted to allow its application to test functions, for example:

@pytest.mark.asyncio_event_loop(
    policy=[
        DefaultEventLoopPolicy(),
        CustomEventLoopPolicy(),
    ]
)
async def test_should_run_twice():
    pass

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions