-
Notifications
You must be signed in to change notification settings - Fork 160
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
Async test function gets skipped with asyncio_mode = auto
and @unittest.mock.patch.dict
decorator
#403
Comments
This also happens when other marks are applied. @pytest.mark.integration
async def test_runs():
... The test gets skipped with the same warning listed above when running As above applying the decorator fixes it: @pytest.mark.integration
@pytest.mark.asyncio
async def test_runs():
... |
On closer inspection after looking at this issue I see our tests that are skipped are also marked with a patch |
When I did a test a couple of days ago I could reproduce the issue with In my opinion there are two things to be done here:
|
In our code base it has been hard for me to track down the exact cause because it has shown up in some places I didn't expect and not in some I did. I know we do have I looked into it some with |
I opened a CPython issue regarding this: python/cpython#98086 |
This comment was marked as spam.
This comment was marked as spam.
The issue has been resolved for CPython 3.12 and the patch was backported to CPython 3.10 and CPython 3.11. 3.10.9 is scheduled for 2022-12-05 and 3.11.1 should be released in December as well. CPython 3.7 is not affected by this bug, but the question is if we want to include a workaround for 3.8 and 3.9. |
The issue continues to be valid. If anyone wants to resolve it for Python 3.8 or 3.9, they're welcome to provide a backport that can be included in pytest-asyncio. |
Python 3.8 is no longer supported by recent versions of pytest-asyncio. A backport of this issue would still be accepted, since we support Python 3.9. However, Python 3.9 reaches end-of-life in October 2025, at which point this issue can be closed anyway. |
Hi!
In a PR for a project I'm working on, an async test method gets skipped with a
PytestUnhandledCoroutineWarning
even thoughpytest-asyncio
is installed andasyncio_mode
isauto
. I poked at it for while and found that this is because the method was decorated with@unittest.mock.patch.dict(...)
. Here's a minimal reproducer which exposes the issue with Python 3.10.6, pytest-7.1.2, pytest-asyncio-0.19.0:--- 8< --- test_the_things.py ---
--- >8 ---
Here's the output I get:
Either without the decorator or by explicitly adding
@pytest.mark.asyncio
the async test functions don't get skipped.The text was updated successfully, but these errors were encountered: