From c838d055701e67dc2cae5f1898d95a65621ff7cf Mon Sep 17 00:00:00 2001 From: pctablet505 <55033230+pctablet505@users.noreply.github.com> Date: Mon, 2 Nov 2026 12:03:44 +0530 Subject: [PATCH] Use --assert=plain in tests that count warnings of an in-process runpytest When the suite runs from an unpacked sdist via the pytest console script, the inner runpytest() sees the shipped egg-info, marks the already imported tests package for assertion rewriting and emits an extra PytestAssertRewriteWarning, breaking exact warning counts. Fixes #1334 --- changelog.d/1334.downstream.rst | 1 + tests/markers/test_class_scope.py | 2 +- tests/markers/test_function_scope.py | 4 +++- tests/markers/test_module_scope.py | 2 +- tests/markers/test_session_scope.py | 2 +- tests/test_event_loop_fixture.py | 8 ++++++-- 6 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 changelog.d/1334.downstream.rst diff --git a/changelog.d/1334.downstream.rst b/changelog.d/1334.downstream.rst new file mode 100644 index 00000000..7aa9dda0 --- /dev/null +++ b/changelog.d/1334.downstream.rst @@ -0,0 +1 @@ +Fixed six tests that failed with ``PytestAssertRewriteWarning`` when the test suite is run from an unpacked sdist using the ``pytest`` command. diff --git a/tests/markers/test_class_scope.py b/tests/markers/test_class_scope.py index 45583c3a..cecd4ec5 100644 --- a/tests/markers/test_class_scope.py +++ b/tests/markers/test_class_scope.py @@ -197,5 +197,5 @@ class TestClass: async def test_anything(self): pass """)) - result = pytester.runpytest("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict", "--assert=plain") result.assert_outcomes(warnings=0, passed=1) diff --git a/tests/markers/test_function_scope.py b/tests/markers/test_function_scope.py index 99ebe5c5..07278596 100644 --- a/tests/markers/test_function_scope.py +++ b/tests/markers/test_function_scope.py @@ -77,7 +77,9 @@ def test_warns_when_scope_argument_is_present(pytester: Pytester): async def test_warns(): ... """)) - result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") + result = pytester.runpytest( + "--asyncio-mode=strict", "-W", "default", "--assert=plain" + ) result.assert_outcomes(passed=1, warnings=1) result.stdout.fnmatch_lines("*DeprecationWarning*") diff --git a/tests/markers/test_module_scope.py b/tests/markers/test_module_scope.py index a814a9d7..64d5f7d7 100644 --- a/tests/markers/test_module_scope.py +++ b/tests/markers/test_module_scope.py @@ -189,5 +189,5 @@ def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_be async def test_anything(): pass """)) - result = pytester.runpytest("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict", "--assert=plain") result.assert_outcomes(warnings=0, passed=1) diff --git a/tests/markers/test_session_scope.py b/tests/markers/test_session_scope.py index 07ccdaa7..265b1a2b 100644 --- a/tests/markers/test_session_scope.py +++ b/tests/markers/test_session_scope.py @@ -292,5 +292,5 @@ def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_be async def test_anything(): pass """)) - result = pytester.runpytest("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict", "--assert=plain") result.assert_outcomes(warnings=0, passed=1) diff --git a/tests/test_event_loop_fixture.py b/tests/test_event_loop_fixture.py index 8902511b..78a09122 100644 --- a/tests/test_event_loop_fixture.py +++ b/tests/test_event_loop_fixture.py @@ -24,7 +24,9 @@ async def generator_fn(): gen = generator_fn() await gen.__anext__() """)) - result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") + result = pytester.runpytest( + "--asyncio-mode=strict", "-W", "default", "--assert=plain" + ) result.assert_outcomes(passed=1, warnings=0) @@ -77,5 +79,7 @@ async def fail(): raise RuntimeError("mock error cleaning up...") loop.shutdown_asyncgens = fail """)) - result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") + result = pytester.runpytest( + "--asyncio-mode=strict", "-W", "default", "--assert=plain" + ) result.assert_outcomes(passed=1, warnings=1)