Our build framework sets PYTEST_PLUGINS to contain 'asyncio' and so the pytest_plugins = 'pytest_asyncio' line tries to load the plugin 2nd time. This emits additional warning and so all tests that check the expected number of warnings fails here. --- pytest_asyncio-0.24.0/tests/hypothesis/test_base.py.orig +++ pytest_asyncio-0.24.0/tests/hypothesis/test_base.py @@ -41,7 +41,7 @@ assert y in (1, 2) -def test_can_use_explicit_event_loop_fixture(pytester: Pytester): +def test_can_use_explicit_event_loop_fixture(pytester: Pytester, monkeypatch): pytester.makepyfile( dedent( """\ @@ -50,8 +50,6 @@ from hypothesis import given import hypothesis.strategies as st - pytest_plugins = 'pytest_asyncio' - @pytest.fixture(scope="module") def event_loop(): loop = asyncio.get_event_loop_policy().new_event_loop() @@ -67,6 +65,7 @@ """ ) ) + monkeypatch.setenv("PYTEST_PLUGINS", "asyncio") result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") result.assert_outcomes(passed=1, warnings=2) result.stdout.fnmatch_lines( --- pytest_asyncio-0.24.0/tests/test_event_loop_fixture_finalizer.py.orig +++ pytest_asyncio-0.24.0/tests/test_event_loop_fixture_finalizer.py @@ -92,7 +92,7 @@ def test_event_loop_fixture_finalizer_raises_warning_when_fixture_leaves_loop_unclosed( - pytester: Pytester, + pytester: Pytester, monkeypatch, ): pytester.makepyfile( dedent( @@ -100,8 +100,6 @@ import asyncio import pytest - pytest_plugins = 'pytest_asyncio' - @pytest.fixture def event_loop(): loop = asyncio.get_event_loop_policy().new_event_loop() @@ -113,13 +111,14 @@ """ ) ) + monkeypatch.setenv("PYTEST_PLUGINS", "asyncio") result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default") result.assert_outcomes(passed=1, warnings=2) result.stdout.fnmatch_lines("*unclosed event loop*") def test_event_loop_fixture_finalizer_raises_warning_when_test_leaves_loop_unclosed( - pytester: Pytester, + pytester: Pytester, monkeypatch, ): pytester.makepyfile( dedent( @@ -127,14 +126,13 @@ import asyncio import pytest - pytest_plugins = 'pytest_asyncio' - @pytest.mark.asyncio async def test_ends_with_unclosed_loop(): asyncio.set_event_loop(asyncio.new_event_loop()) """ ) ) + monkeypatch.setenv("PYTEST_PLUGINS", "asyncio") result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default") result.assert_outcomes(passed=1, warnings=1) result.stdout.fnmatch_lines("*unclosed event loop*")