-
Notifications
You must be signed in to change notification settings - Fork 146
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
Would you find it useful if you could reliably fail tests that have unawaited coroutines? #67
Comments
Well, since you explained it so nicely, I'd be interested of course :) |
I just hit this one twice in a row. |
ditto |
Absolutely yes; I can say I've come across tests that were never running for an appreciable amount of time because of this, combined with #77 ; failing the test would have prompted the author to abandon converting to unittest |
If you're using mypy (can also be integrated into CI), you can catch this statically: https://mypy.readthedocs.io/en/stable/error_code_list2.html#check-that-awaitable-return-value-is-used-unused-awaitable Ruff might also add this: astral-sh/ruff#9911 |
Right now, this test passes:
The reason is that we forgot the
await
intest_something_broken
, so the broken code never actually ran. Oops. Python does issue aRuntimeWarning: coroutine 'do_something_broken' was never awaited
, and recent pytest will print this at the end of tests, but this has a few issues:I'm considering proposing a new feature for Python 3.7, that would make it so pytest-asyncio could do:
(Names etc. to be bikeshedded later; this is "API 2" in python-trio/trio#79 (comment))
This way you could deterministically detect unawaited coroutines, reliably attribute them to the correct test, and cause it to fail with a useful error message.
Is this an API that you'd want to take advantage of if it were available?
The text was updated successfully, but these errors were encountered: