Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
seifertm opened this issue Oct 24, 2023 · 2 comments
Closed

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

seifertm opened this issue Oct 24, 2023 · 2 comments

Comments

@seifertm
Copy link
Contributor

#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
@seifertm seifertm changed the title Allow the _asyncio_event_loop_ mark to be applied to test coroutines Allow the *asyncio_event_loop* mark to be applied to test coroutines Oct 24, 2023
@seifertm seifertm changed the title Allow the *asyncio_event_loop* mark to be applied to test coroutines Allow the asyncio_event_loop mark to be applied to test coroutines Oct 24, 2023
@seifertm seifertm added this to the v0.22 milestone Oct 24, 2023
@seifertm
Copy link
Contributor Author

My first try at implementing this didn't succeed.

The setup of asyncio_event_loop needs to happen before pytest_generate_tests. For classes and modules this is done in pytest_collectstart. Unfortunately, this hook doesn't seem to be called for pytest.Function items.

@seifertm seifertm removed this from the v0.22 milestone Oct 29, 2023
@seifertm
Copy link
Contributor Author

seifertm commented Nov 8, 2023

The asyncio_event_loop mark has been abandoned in favour of the scope kwarg to the asyncio mark.
see #657

@seifertm seifertm closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant