-
Notifications
You must be signed in to change notification settings - Fork 145
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
Task finalizers run outside of event loop #878
Comments
Thanks for the report and the reproducer!
I don't think we can address this issue anytime soon. |
Thanks for the response! Honestly, up until I discovered this bug, I just assumed that pytest-asyncio was a simple wrapper around |
I think the straightforward reason is legacy. Pytest-asyncio has been around for some time and the asyncio API is evolving. A lot of the low-level asyncio calls used by pytest-asyncio have been (partially) deprecated. The current plan for pytest-asyncio is to move to using |
Something about how pytest-asyncio is handling finalizers isn't working right. When a task is abandoned by a test, the task's finalizers get run outside of the event loop, meaning any async cleanup will not be run. The following test fails with pytest-asyncio, but works fine if you switch to using
asyncio.run
.I encountered this issue because my cleanup code was calling
ContextVar.reset
, and it would emit a warning (shown below), and I believe this is the root cause.Python 3.11.9
Pytest 8.2.2
pytest-asyncio 0.23.7
The text was updated successfully, but these errors were encountered: