-
Notifications
You must be signed in to change notification settings - Fork 151
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
Python 3.11: DeprecationWarning: There is no current event loop #757
Comments
Which version of pytest-asyncio are you using? |
Hi! I encountered same issue Versions:
Here's traceback /python3.12/site-packages/pytest_asyncio/plugin.py:656: DeprecationWarning: There is no current event loop
old_loop = asyncio.get_event_loop() |
I think this only happens on the older version of python? After upgrading from python 3.11.0rc1 to 3.11.7, the warning no longer shows up.
The warning did shows up on older version of python before I updated it.
import pytest
@pytest.mark.asyncio
async def test():
pass The docs has a footnote on the warning, so it would probably only show up on 3.10.0–3.10.8 and 3.11.0:
|
When using I used the same test that @asl97 provided above.
|
I also still see it with 3.12.1 and strict mode: pytest==8.0.0 the warning no longer shows up when i remove my async fixture however that I use to init my database:
Alternatively the warning also disappears once I no longer specify:
|
Pytest-asyncio still uses |
Just tried out the latest, unfortunately, seems like the problem still persists:
|
@AivanF could this be an interaction with anyio (do you have @pytest.mark.anyio ?) or any calls to |
We have the same problem in our project.
The test function looks like this (minimal test that doesn't use anything from the rest of the project): @pytest.mark.asyncio
async def test_async_foo():
async def foo():
return 42
assert await foo() == 42 |
@AivanF @binaryDiv both your versions are older than 3.10.9. @seifertm should this issue remain open just for issue on older python version which explicitly mentions would give an warning in the docs, and which would probably go away as soon as they update to a newer 3.10? |
@asl97 Excellent question The way the deprecation of The stack trace suggests that the line 904 of the following function triggers the warning: pytest-asyncio/pytest_asyncio/plugin.py Lines 901 to 914 in b22d84e
This is the reason why I reopened the issue. Until pytest-asyncio moves away from the use of pytest-asyncio/pytest_asyncio/plugin.py Lines 669 to 674 in b22d84e
I'd be grateful to anyone who contributes a patch with an accompanying regression test added to the test suite. If I recall correctly, there are a number of places where get_event_loop is called with the pattern illustrated in the lattes example. In that case, it would be even better if the patch deduplicated the code by extracting the above snippet to a dedicated function. |
FYI: Currently you can suppress this warning with
This workaround suits me since I'll never manually create an event loop in my program, thus the option will not blindly suppress warnings generated from my code. |
Pytest-asyncio v0.23.7 has been released. It includes a patch contributed by @SyntaxColoring which should resolve the issue, even with specific CPython patch versions. |
FWIW, upgrading to pytest-asyncio v0.23.7 did not work for me. I am running Python 3.12.3 |
@algebraist Can you provide a minimal reproducer, so we can verify if this and your issue have the same cause? |
@seifertm I think my issue may be different actually. I trigger the deprecation warning when I have a single line in a python script:
I was running pytest on files that were importing ib_async, and that was likely triggering the deprecation. The ib_async maintainers are aware of my issue. Thanks for responding! |
When running the test suite on Python 3.11, tests with a
@pytest.mark.asyncio
decorator, trigger a DeprecationWarning:The text was updated successfully, but these errors were encountered: