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.25.0/tests/hypothesis/test_base.py.orig +++ pytest_asyncio-0.25.0/tests/hypothesis/test_base.py @@ -45,7 +45,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.makeini("[pytest]\nasyncio_default_fixture_loop_scope = module") pytester.makepyfile( dedent( @@ -55,8 +55,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() @@ -72,6 +70,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.25.0/tests/test_event_loop_fixture_finalizer.py.orig +++ pytest_asyncio-0.25.0/tests/test_event_loop_fixture_finalizer.py @@ -98,7 +98,7 @@ def test_event_loop_fixture_finalizer_raises_warning_when_fixture_leaves_loop_unclosed( - pytester: Pytester, + pytester: Pytester, monkeypatch, ): pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( @@ -107,8 +107,6 @@ import asyncio import pytest - pytest_plugins = 'pytest_asyncio' - @pytest.fixture def event_loop(): loop = asyncio.get_event_loop_policy().new_event_loop() @@ -120,13 +118,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.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( @@ -135,14 +134,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*")