diff --git a/changelog.d/1334.downstream.rst b/changelog.d/1334.downstream.rst new file mode 100644 index 00000000..653c9adc --- /dev/null +++ b/changelog.d/1334.downstream.rst @@ -0,0 +1 @@ +Avoided a ``PytestAssertRewriteWarning`` in the test suite when it is run from an unpacked sdist. The sdist ships ``pytest_asyncio.egg-info/SOURCES.txt``, which lists ``tests/__init__.py``, so pytest marks the ``tests`` package for assertion rewriting even though it has already been imported by the outer session. This affects downstream distributors such as Guix. diff --git a/tests/markers/test_class_scope.py b/tests/markers/test_class_scope.py index 28f7187c..4ee6951f 100644 --- a/tests/markers/test_class_scope.py +++ b/tests/markers/test_class_scope.py @@ -274,5 +274,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 180d5c71..1e797895 100644 --- a/tests/markers/test_function_scope.py +++ b/tests/markers/test_function_scope.py @@ -72,7 +72,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 a2662812..c1e6ff99 100644 --- a/tests/markers/test_module_scope.py +++ b/tests/markers/test_module_scope.py @@ -281,5 +281,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 24566c5e..6cd85a55 100644 --- a/tests/markers/test_session_scope.py +++ b/tests/markers/test_session_scope.py @@ -392,5 +392,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..e27d27b5 100644 --- a/tests/test_event_loop_fixture.py +++ b/tests/test_event_loop_fixture.py @@ -13,8 +13,6 @@ def test_event_loop_fixture_handles_unclosed_async_gen( import asyncio import pytest - pytest_plugins = 'pytest_asyncio' - @pytest.mark.asyncio async def test_something(): async def generator_fn(): @@ -24,7 +22,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) @@ -67,8 +67,6 @@ def test_event_loop_fixture_asyncgen_error( import asyncio import pytest - pytest_plugins = 'pytest_asyncio' - @pytest.mark.asyncio async def test_something(): # mock shutdown_asyncgen failure @@ -77,5 +75,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)