-
Notifications
You must be signed in to change notification settings - Fork 159
Warning not getting raised within test #426
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
Comments
Thanks for the report. I believe you couldn't get a minimal reproducible example, because the behaviour is non-deterministic. I tried as well. I started with the aiojobs repository and removed pieces of code. Eventually I ended up with this:
Pytest didn't show a warning in the report, but the console clearly printed a warning:
When I changed the test name to
I tried going back to the old behaviour by re-adding the I am quite certain that this has nothing to do with pytest-asyncio. You can see that I have disabled the plugin entirely for the example. Luckily, I recently checked out the CPython repo, so I could start sleuthing there :) |
It seems that
The above code prints:
I assume that the task generally outlives the pytest session, because it is still referenced somewhere. That also explains why an explicit call to We can try raising this issue to pytest, but it's unlikely they can do anything about it. Maybe they have more ideas, though. @Dreamsorcerer As a workaround, you can try the following patch to aiojobs, which circumvents the reported issue by provoking a RuntimeError before creating a coroutine.
|
That does seem like an awful lot. The first example just creates a coroutine object though, without scheduling it in the event loop, so it obviously wouldn't have references elsewhere. |
I agree, the comparison is wrong. The day was long… :) |
There has been work in pytest to correctly treat warnings like the one reported: pytest-dev/pytest#8021 Pytest tries to catch these warnings with the unraisableexception plugin.. I could see a difference when running this code with However, I couldn't see different behaviour in aiojobs. I disabled all pytest configuration in |
I managed to create a reproducible example and reported the bug to upstream: |
Thanks for delving into that in such depth. |
When running pytest on aiojobs, I get a warning printed out in the output, but it fails to trigger anything in the test that caused it. We have warnings set to error, so this should result in a test failure. As far as I can tell, the warning appears to be happening outside the test run, even though it is clearly something that was caused inside the test.
I've tried to reproduce it without the aiojobs code, but simpler reproducers always result in the correct behaviour, with the test failing. I've got no idea what might be causing this test to get handled differently (also not sure if this might be an issue with pytest itself).
Output from the test run looks like:
The cause is the last test (https://github.com/aio-libs/aiojobs/pull/352/files#diff-7cab305a6a78540131fcce1fafb912ccf6b52aa50b4a0a2b794aea71004d5a95R433):
Within
Scheduler
it runsasyncio.create_task(coro())
, which causes theRuntimeError
we are testing for due to there being no loop. Then when coro() is garbage collected, theRuntimeWarning
would be triggered due to it never getting awaited.Expected behaviour is for that last test to fail due to the warning.
The text was updated successfully, but these errors were encountered: