-
Notifications
You must be signed in to change notification settings - Fork 160
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
Event loop is closed
when using pytester
and pytest_asyncio.fixture(autouse=True)
#291
Comments
Thanks for the report! I can reproduce the issue with your example. My current understanding is that the programmatic pytest run using Modifying the event_loop fixture scope will not change anything, probably because pytester.runpytest represents a full test session. The example repository presents two workarounds. One workaround is to redefine the event_loop fixture inside Both are workarounds, so I don't think it makes sense to revert to an earlier version of pytest-asyncio. This is a tricky one to solve… Ideally, we would like An alternative is to whip up some custom logic specifically for tests requesting the I'm sorry that I don't have any immediate fix for this. At the moment, I'd say this issue is blocked by #235. If you have any suggestions, I'd be happy to hear them. |
@unmade Does it solve the issue if you use pytester.runpytest_subprocess rather than |
I can no longer reproduce the issue using the code in the linked repository with pytest-asyncio 0.19.0. I checked CPython 3.7 up to v3.10. Please reopen if you happen to run into this problem again. |
How to simplify this in async test?
|
@crypto-only You'd only use Your example can be simplified by setting
There is no need to use pytester in your example. |
If you have an async fixture with a teardown and
autouse=True
and you have a simple non-async test with a pytester plugin, then that fixture is always added as a finalizer.Basically, if you have the following:
Then, the test fails on a teardown with the following error:
I've checked it on
pytest-asyncio==0.16.0
andpytest>=0.17.0
. However, prior v0.17.0 there was a workaround - you could redefine anevent_loop
in a temporary pytest test file without closing the loop. Since, v0.17.0 this is no longer possible.In v0.17.0 the only workaround is to override this async fixture itself in temporary pytest test file.
I made a minimal reproducible example, you can find it here:
https://github.com/unmade/pytester-pytest-asyncio-bug
The text was updated successfully, but these errors were encountered: