-
Notifications
You must be signed in to change notification settings - Fork 149
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
Pytest hook to mark all async tests with scope=session not working when using async fixtures #705
Comments
Thanks for the report and the great reproducer!
When I change I have to investigate with regards to both problems. |
Regarding your workaround: Rather than marking each test individually, you could consider marking modules or even packages using pytestmark, until this is fixed. See also: |
Thanks for the quick response. I have tried marking it by package (
|
First of all, thank for this package and for maintaining it! ❤️
Here I just want to add that it's not always possible to switch from |
@albertferras-vrf The |
@seifertm the thing is that I have no test explicitly requesting the
|
Chiming in to say that I too have gotten MultipleEventLoopsRequestedError, when no test in the codebase (and certainly not the one reported in the message) requests |
After spending some time trying to fix this issue, I finally gave up and decided to switch to pytest-aio. No need for overriding Sorry for posting this here, thought this might save someone else. |
I think I experienced the same problem reported by albertferras-vrf in the first post, and I think I fixed it by adding async_test.add_marker(session_scope_marker, append=False) If anyone tries this, please confirm whether it works or if I'm just imagining it. It makes sense to me that this would fix it. I would love to have the ability to specify the event loop scope via configuration. e.g. If I could set |
Just want to mention one other observation: If I have an autouse fixture with scope="function", that appears to cause my tests to run in separate event loops even when following the "How to run all tests in the session in the same event loop" with the |
@markdoliner Thanks for the investigation. I can confirm that adding This seems to be an issue with the order of the asyncio marks. Each pytest node can have the same mark multiple times. Changing the behavior of This also means it's not possible to override the loop scope with an explicit I'm planning to do a .post release of pytest-asyncio with updated documentation and close this issue. |
Well it saved me. I've been battling a similar issue for days, loop related errors for seemingly no reason, saw your comment and tried it and after about 5 minutes of cleaning up fixtures everything just worked. Thanks. |
I have followed instructions from https://pytest-asyncio.readthedocs.io/en/latest/how-to-guides/run_session_tests_in_same_loop.html to add the
pytest.mark.asyncio(scope="session")
to all my async tests.The problem I'm having is that, when these tests contain an async session-scoped fixture, the tests fail with
RunTimeError: Event loop is closed
.If I manually add the
@pytest.mark.asyncio(scope="session")
mark on my tests (one by one, without using the pytest hook) then it works fine.This reproduces the issue. Using
pytest-asyncio==0.23.2
andpytest==7.4.3
onpython 3.11.16
. I also haveasyncio_mode=auto
in case it's relevantconftest.py
test_hello.py
The text was updated successfully, but these errors were encountered: