Skip to content

Commit 007e8ec

Browse files
authored
[fix] Prevent DeprecationWarning about existing event loops to bubble up into user code. (#461)
Pytest-asyncio fixture setup currently uses `get_event_loop` to clean up loops that don't correspond to the loop returned by the `event_loop` fixture. Starting with CPython 3.10.9 and 3.11.1 the call to get_event_loop emits a DeprecationWarning when function is called, but no event loop exists. This warning bubbles up and shows in test runs of library users. If the users have enabled `-W error` their tests will fail due to a warning in pytest-asyncio. This patch ignores the DeprecationWarning in the fixture setup. This is a temporary solution to restore compatibility with the respective CPython patch releases. Addresses #460 Signed-off-by: Michael Seifert <[email protected]> Signed-off-by: Michael Seifert <[email protected]>
1 parent 44ca3da commit 007e8ec

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
=========
44

5+
0.20.3 (22-12-08)
6+
=================
7+
- Prevent DeprecationWarning to bubble up on CPython 3.10.9 and 3.11.1.
8+
`#460 <https://github.com/pytest-dev/pytest-asyncio/issues/460>`_
9+
510
0.20.2 (22-11-11)
611
=================
712
- Fixes an issue with async fixtures that are defined as methods on a test class not being rebound to the actual test instance. `#197 <https://github.com/pytest-dev/pytest-asyncio/issues/197>`_

pytest_asyncio/plugin.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ def pytest_fixture_setup(
399399
loop = outcome.get_result()
400400
policy = asyncio.get_event_loop_policy()
401401
try:
402-
old_loop = policy.get_event_loop()
402+
with warnings.catch_warnings():
403+
warnings.simplefilter("ignore", DeprecationWarning)
404+
old_loop = policy.get_event_loop()
403405
if old_loop is not loop:
404406
old_loop.close()
405407
except RuntimeError:

0 commit comments

Comments
 (0)