| 1 |
From: Colin Watson <[email protected]> |
| 2 |
Date: Wed, 10 Sep 2025 01:00:47 +0100 |
| 3 |
Subject: tests: Ignore warning when running with installed pytest_asyncio |
| 4 |
|
| 5 |
This happens in autopkgtests. |
| 6 |
|
| 7 |
Forwarded: not-needed |
| 8 |
Last-Update: 2026-06-03 |
| 9 |
--- |
| 10 |
tests/test_event_loop_fixture.py | 15 +++++++++++++-- |
| 11 |
tests/test_set_event_loop.py | 11 ++++++++++- |
| 12 |
2 files changed, 23 insertions(+), 3 deletions(-) |
| 13 |
|
| 14 |
diff --git a/tests/test_event_loop_fixture.py b/tests/test_event_loop_fixture.py |
| 15 |
index 8902511..feaedb2 100644 |
| 16 |
--- a/tests/test_event_loop_fixture.py |
| 17 |
+++ b/tests/test_event_loop_fixture.py |
| 18 |
@@ -5,6 +5,13 @@ from textwrap import dedent |
| 19 |
from pytest import Pytester |
| 20 |
|
| 21 |
|
| 22 |
+_ignore_installed_warning = ( |
| 23 |
+ "ignore" |
| 24 |
+ ":Module already imported so cannot be rewritten; pytest_asyncio" |
| 25 |
+ ":pytest.PytestAssertRewriteWarning" |
| 26 |
+) |
| 27 |
+ |
| 28 |
+ |
| 29 |
def test_event_loop_fixture_handles_unclosed_async_gen( |
| 30 |
pytester: Pytester, |
| 31 |
): |
| 32 |
@@ -24,7 +31,9 @@ def test_event_loop_fixture_handles_unclosed_async_gen( |
| 33 |
gen = generator_fn() |
| 34 |
await gen.__anext__() |
| 35 |
""")) |
| 36 |
- result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") |
| 37 |
+ result = pytester.runpytest( |
| 38 |
+ "--asyncio-mode=strict", "-W", "default", "-W", _ignore_installed_warning |
| 39 |
+ ) |
| 40 |
result.assert_outcomes(passed=1, warnings=0) |
| 41 |
|
| 42 |
|
| 43 |
@@ -77,5 +86,7 @@ def test_event_loop_fixture_asyncgen_error( |
| 44 |
raise RuntimeError("mock error cleaning up...") |
| 45 |
loop.shutdown_asyncgens = fail |
| 46 |
""")) |
| 47 |
- result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") |
| 48 |
+ result = pytester.runpytest( |
| 49 |
+ "--asyncio-mode=strict", "-W", "default", "-W", _ignore_installed_warning |
| 50 |
+ ) |
| 51 |
result.assert_outcomes(passed=1, warnings=1) |
| 52 |
diff --git a/tests/test_set_event_loop.py b/tests/test_set_event_loop.py |
| 53 |
index 52dfc7a..746ba34 100644 |
| 54 |
--- a/tests/test_set_event_loop.py |
| 55 |
+++ b/tests/test_set_event_loop.py |
| 56 |
@@ -7,6 +7,13 @@ import pytest |
| 57 |
from pytest import Pytester |
| 58 |
|
| 59 |
|
| 60 |
+_ignore_installed_warning = ( |
| 61 |
+ "ignore" |
| 62 |
+ ":Module already imported so cannot be rewritten; pytest_asyncio" |
| 63 |
+ ":pytest.PytestAssertRewriteWarning" |
| 64 |
+) |
| 65 |
+ |
| 66 |
+ |
| 67 |
@pytest.mark.parametrize( |
| 68 |
"test_loop_scope", |
| 69 |
("function", "module", "package", "session"), |
| 70 |
@@ -129,7 +136,9 @@ def test_asyncio_run_after_async_fixture_does_not_leak_loop( |
| 71 |
asyncio.run(amain()) |
| 72 |
gc.collect() |
| 73 |
""")) |
| 74 |
- result = pytester.runpytest_subprocess("-W", "error") |
| 75 |
+ result = pytester.runpytest_subprocess( |
| 76 |
+ "-W", "error", "-W", _ignore_installed_warning |
| 77 |
+ ) |
| 78 |
result.assert_outcomes(passed=2) |
| 79 |
|
| 80 |
|