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)
