You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason is that we forgot the await in test_something_broken, so the broken code never actually ran. Oops. Python does issue a RuntimeWarning: coroutine 'do_something_broken' was never awaited, and recent pytest will print this at the end of tests, but this has a few issues:
if your CI is green then how often do you click through to check for non-fatal warnings?
since the warning isn't issued until the coroutine is garbage collected, on PyPy this can happen in some random other test, or if the test is near the end of the run it might never happen at all. E.g. with latest pypy3, pytest, and pytest-asyncio, the above test doesn't issue any warnings at all:
I'm considering proposing a new feature for Python 3.7, that would make it so pytest-asyncio could do:
# Ask Python to start maintaining a list of unawaited coroutinessys.set_unawaited_coroutine_tracking(True)
try:
... runthetest ...
finally:
# Get the unawaited coroutinesunawaited_coroutines=sys.get_and_clear_unawaited_coroutines()
sys.set_unawaited_coroutine_tracking(False)
ifunawaited_coroutines:
# Issue an error that points to the actual problemraiseRuntimeError(f"Unawaited coroutines: {unawaited_coroutines}")
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:
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
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: