-
Notifications
You must be signed in to change notification settings - Fork 152
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
During cleanup, should pytest-asyncio cancel outstanding tasks, shut down async generators, and shut down the thread pool, like asyncio.run()
does?
#222
Comments
asyncio.run()
does?
asyncio.run()
does?asyncio.run()
does?
Echoing this - I just spent a while figuring out where the heck these 'async generator not closed' warnings were coming from in my test suite, when I couldn't reproduce the behaviour in prod. |
+1 Got a bunch of "Task was destroyed but it is pending!" because tasks weren't allowed to handle cancellation and finish. |
Yeah, this seems like a good change to make. I'll take a PR or implement this myself in the next couple of weeks. |
Can be solved as a side-effect of #235 |
Here's how
pytest-asyncio
implements theevent_loop
fixture:pytest-asyncio/pytest_asyncio/plugin.py
Lines 224 to 229 in 6ec7647
Note that
loop.close()
is the sole cleanup code.Compare this with the implementation of
asyncio.run()
:Before calling
loop.close()
,asyncio.run()
does this:_cancel_all_tasks()
.loop.shutdown_asyncgens()
loop.shutdown_default_executor()
.(I think (2) and (3) correspond to what the documentation calls "finalizing asynchronous generators and closing the threadpool.")
I only have a tenuous grasp on these
asyncio
internals, but it seems like theevent_loop
fixture should do this, too? And so should any other place inpytest-asyncio
where the event loop is shut down, if there are more.The text was updated successfully, but these errors were encountered: