1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
From: Colin Watson <cjwatson@debian.org>
Date: Wed, 10 Sep 2025 01:00:47 +0100
Subject: tests: Ignore warning when running with installed pytest_asyncio
This happens in autopkgtests.
Forwarded: not-needed
Last-Update: 2025-10-10
---
tests/test_event_loop_fixture.py | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/tests/test_event_loop_fixture.py b/tests/test_event_loop_fixture.py
index 8b9ac63..2ed0872 100644
--- a/tests/test_event_loop_fixture.py
+++ b/tests/test_event_loop_fixture.py
@@ -5,6 +5,13 @@ from textwrap import dedent
from pytest import Pytester
+_ignore_installed_warning = (
+ "ignore"
+ ":Module already imported so cannot be rewritten; pytest_asyncio"
+ ":pytest.PytestAssertRewriteWarning"
+)
+
+
def test_event_loop_fixture_respects_event_loop_policy(pytester: Pytester):
pytester.makeconftest(
dedent(
@@ -78,7 +85,9 @@ def test_event_loop_fixture_handles_unclosed_async_gen(
"""
)
)
- result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default")
+ result = pytester.runpytest_subprocess(
+ "--asyncio-mode=strict", "-W", "default", "-W", _ignore_installed_warning
+ )
result.assert_outcomes(passed=1, warnings=0)
@@ -110,7 +119,9 @@ def test_closing_event_loop_in_sync_fixture_teardown_raises_warning(
"""
)
)
- result = pytester.runpytest_subprocess("--asyncio-mode=strict")
+ result = pytester.runpytest_subprocess(
+ "--asyncio-mode=strict", "-W", _ignore_installed_warning
+ )
result.assert_outcomes(passed=1, warnings=1)
result.stdout.fnmatch_lines(
["*An exception occurred during teardown of an asyncio.Runner*"]
@@ -139,5 +150,7 @@ def test_event_loop_fixture_asyncgen_error(
"""
)
)
- result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default")
+ result = pytester.runpytest_subprocess(
+ "--asyncio-mode=strict", "-W", "default", "-W", _ignore_installed_warning
+ )
result.assert_outcomes(passed=1, warnings=1)
|