From ebb565c07e6c8e8d24aece21c0628348d24003a7 Mon Sep 17 00:00:00 2001 From: "joao.faria" Date: Fri, 31 Oct 2025 13:52:12 -0300 Subject: [PATCH 1/5] fix(tests): replace runpytest_subprocess with runpytest - runpytest_subprocess uses system-installed pytest-asyncio instead of development version, causing typeerror when tests needs to use loop_scope parameter --- changelog.d/1275.downstream.rst | 1 + tests/hypothesis/test_base.py | 2 +- tests/markers/test_class_scope.py | 6 +++--- tests/markers/test_invalid_arguments.py | 8 ++++---- tests/markers/test_module_scope.py | 6 +++--- tests/markers/test_package_scope.py | 4 ++-- tests/markers/test_session_scope.py | 6 +++--- tests/modes/test_strict_mode.py | 8 ++++---- tests/test_asyncio_mark.py | 14 +++++++------- tests/test_event_loop_fixture.py | 8 ++++---- tests/test_fixture_loop_scopes.py | 10 +++++----- tests/test_set_event_loop.py | 6 +++--- 12 files changed, 40 insertions(+), 39 deletions(-) create mode 100644 changelog.d/1275.downstream.rst diff --git a/changelog.d/1275.downstream.rst b/changelog.d/1275.downstream.rst new file mode 100644 index 00000000..3df2e557 --- /dev/null +++ b/changelog.d/1275.downstream.rst @@ -0,0 +1 @@ +Tests are run in the same pytest process, instead of spawning a subprocess with `pytest.Pytester.runpytest_subprocess`. This prevents the test suite from accidentally using a system installation of pytest-asyncio, which could result in test errors. diff --git a/tests/hypothesis/test_base.py b/tests/hypothesis/test_base.py index 487b05fe..76392ee5 100644 --- a/tests/hypothesis/test_base.py +++ b/tests/hypothesis/test_base.py @@ -27,7 +27,7 @@ async def test_mark_inner(n): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest("--asyncio-mode=strict", "-W default") result.assert_outcomes(passed=1) diff --git a/tests/markers/test_class_scope.py b/tests/markers/test_class_scope.py index e8732e86..300da183 100644 --- a/tests/markers/test_class_scope.py +++ b/tests/markers/test_class_scope.py @@ -175,7 +175,7 @@ async def test_parametrized_loop(self, request): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=2) @@ -205,7 +205,7 @@ async def test_runs_is_same_loop_as_fixture(self, my_fixture): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=1) @@ -293,5 +293,5 @@ async def test_anything(self): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(warnings=0, passed=1) diff --git a/tests/markers/test_invalid_arguments.py b/tests/markers/test_invalid_arguments.py index 2d5c3552..82a68f08 100644 --- a/tests/markers/test_invalid_arguments.py +++ b/tests/markers/test_invalid_arguments.py @@ -19,7 +19,7 @@ async def test_anything(): """ ) ) - result = pytester.runpytest_subprocess() + result = pytester.runpytest("--assert=plain") result.assert_outcomes(passed=1) result.stdout.no_fnmatch_line("*ValueError*") @@ -38,7 +38,7 @@ async def test_anything(): """ ) ) - result = pytester.runpytest_subprocess() + result = pytester.runpytest("--assert=plain") result.assert_outcomes(errors=1) result.stdout.fnmatch_lines( ["*ValueError: mark.asyncio accepts only a keyword argument*"] @@ -59,7 +59,7 @@ async def test_anything(): """ ) ) - result = pytester.runpytest_subprocess() + result = pytester.runpytest("--assert=plain") result.assert_outcomes(errors=1) result.stdout.fnmatch_lines( ["*ValueError: mark.asyncio accepts only a keyword argument 'loop_scope'*"] @@ -80,7 +80,7 @@ async def test_anything(): """ ) ) - result = pytester.runpytest_subprocess() + result = pytester.runpytest("--assert=plain") result.assert_outcomes(errors=1) result.stdout.fnmatch_lines( ["*ValueError: mark.asyncio accepts only a keyword argument*"] diff --git a/tests/markers/test_module_scope.py b/tests/markers/test_module_scope.py index a050f503..5b490b26 100644 --- a/tests/markers/test_module_scope.py +++ b/tests/markers/test_module_scope.py @@ -119,7 +119,7 @@ async def test_parametrized_loop(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=2) @@ -150,7 +150,7 @@ async def test_runs_is_same_loop_as_fixture(my_fixture): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=1) @@ -298,5 +298,5 @@ async def test_anything(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(warnings=0, passed=1) diff --git a/tests/markers/test_package_scope.py b/tests/markers/test_package_scope.py index 3e41459b..26fcd23f 100644 --- a/tests/markers/test_package_scope.py +++ b/tests/markers/test_package_scope.py @@ -160,7 +160,7 @@ async def test_parametrized_loop(): """ ), ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=2) @@ -207,7 +207,7 @@ async def test_runs_in_same_loop_as_fixture(my_fixture): """ ), ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=1) diff --git a/tests/markers/test_session_scope.py b/tests/markers/test_session_scope.py index 2d3a4993..b8d110f1 100644 --- a/tests/markers/test_session_scope.py +++ b/tests/markers/test_session_scope.py @@ -161,7 +161,7 @@ async def test_parametrized_loop(): """ ), ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=2) @@ -212,7 +212,7 @@ async def test_runs_in_same_loop_as_fixture(my_fixture): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=1) @@ -423,5 +423,5 @@ async def test_anything(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(warnings=0, passed=1) diff --git a/tests/modes/test_strict_mode.py b/tests/modes/test_strict_mode.py index d7dc4ac6..0a467c18 100644 --- a/tests/modes/test_strict_mode.py +++ b/tests/modes/test_strict_mode.py @@ -94,7 +94,7 @@ async def test_anything(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain") if pytest_version >= (8, 4, 0): result.assert_outcomes(failed=1, skipped=0, warnings=0) else: @@ -119,7 +119,7 @@ async def test_anything(any_fixture): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain") if pytest_version >= (8, 4, 0): result.assert_outcomes(failed=1, skipped=0, warnings=2) @@ -155,7 +155,7 @@ async def test_anything(any_fixture): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain") if pytest_version >= (8, 4, 0): result.assert_outcomes(passed=1, failed=0, skipped=0, warnings=2) else: @@ -202,7 +202,7 @@ async def test_anything(any_fixture): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain") if pytest_version >= (8, 4, 0): result.assert_outcomes(passed=1, warnings=2) else: diff --git a/tests/test_asyncio_mark.py b/tests/test_asyncio_mark.py index 81731adb..283319c9 100644 --- a/tests/test_asyncio_mark.py +++ b/tests/test_asyncio_mark.py @@ -17,7 +17,7 @@ def test_a(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain") result.assert_outcomes(passed=1) result.stdout.fnmatch_lines( ["*is marked with '@pytest.mark.asyncio' but it is not an async function.*"] @@ -38,7 +38,7 @@ async def test_a(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain") result.assert_outcomes(xfailed=1, warnings=1) result.stdout.fnmatch_lines( ["*Tests based on asynchronous generators are not supported*"] @@ -56,7 +56,7 @@ async def test_a(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=auto", "-W default") + result = pytester.runpytest("--asyncio-mode=auto", "-W default", "--assert=plain") result.assert_outcomes(xfailed=1, warnings=1) result.stdout.fnmatch_lines( ["*Tests based on asynchronous generators are not supported*"] @@ -78,7 +78,7 @@ async def test_a(self): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain") result.assert_outcomes(xfailed=1, warnings=1) result.stdout.fnmatch_lines( ["*Tests based on asynchronous generators are not supported*"] @@ -98,7 +98,7 @@ async def test_a(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=auto", "-W default") + result = pytester.runpytest("--asyncio-mode=auto", "-W default", "--assert=plain") result.assert_outcomes(xfailed=1, warnings=1) result.stdout.fnmatch_lines( ["*Tests based on asynchronous generators are not supported*"] @@ -121,7 +121,7 @@ async def test_a(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest("--asyncio-mode=strict", "-W default", "--assert=plain") result.assert_outcomes(xfailed=1, warnings=1) result.stdout.fnmatch_lines( ["*Tests based on asynchronous generators are not supported*"] @@ -141,7 +141,7 @@ async def test_a(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=auto", "-W default") + result = pytester.runpytest("--asyncio-mode=auto", "-W default", "--assert=plain") result.assert_outcomes(xfailed=1, warnings=1) result.stdout.fnmatch_lines( ["*Tests based on asynchronous generators are not supported*"] diff --git a/tests/test_event_loop_fixture.py b/tests/test_event_loop_fixture.py index 8b9ac634..c67b36d7 100644 --- a/tests/test_event_loop_fixture.py +++ b/tests/test_event_loop_fixture.py @@ -51,7 +51,7 @@ async def test_custom_policy_is_not_overwritten(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=2) @@ -78,7 +78,7 @@ async def generator_fn(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default") + result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") result.assert_outcomes(passed=1, warnings=0) @@ -110,7 +110,7 @@ async def test_something(close_event_loop): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest_subprocess("--asyncio-mode=strict", "--assert=plain") result.assert_outcomes(passed=1, warnings=1) result.stdout.fnmatch_lines( ["*An exception occurred during teardown of an asyncio.Runner*"] @@ -139,5 +139,5 @@ async def fail(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W", "default") + result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") result.assert_outcomes(passed=1, warnings=1) diff --git a/tests/test_fixture_loop_scopes.py b/tests/test_fixture_loop_scopes.py index 95e46818..1fd29350 100644 --- a/tests/test_fixture_loop_scopes.py +++ b/tests/test_fixture_loop_scopes.py @@ -34,7 +34,7 @@ async def test_runs_in_same_loop_as_fixture(fixture): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=1) @@ -68,7 +68,7 @@ async def test_runs_in_fixture_loop(fixture_loop): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=1) @@ -101,7 +101,7 @@ async def test_runs_in_fixture_loop(self, fixture_loop): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=1) @@ -134,7 +134,7 @@ async def test_runs_in_fixture_loop(fixture_loop): """ ), ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=1) @@ -145,7 +145,7 @@ def test_invalid_default_fixture_loop_scope_raises_error(pytester: Pytester): asyncio_default_fixture_loop_scope = invalid_scope """ ) - result = pytester.runpytest() + result = pytester.runpytest("--assert=plain") result.stderr.fnmatch_lines( [ "ERROR: 'invalid_scope' is not a valid " diff --git a/tests/test_set_event_loop.py b/tests/test_set_event_loop.py index 20037b48..a2f5dfaa 100644 --- a/tests/test_set_event_loop.py +++ b/tests/test_set_event_loop.py @@ -173,7 +173,7 @@ async def test_verify_original_loop_reinstated(): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=3) @@ -252,7 +252,7 @@ async def test_after(webserver): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=3) @@ -367,5 +367,5 @@ async def test_after_second(second_webserver): """ ) ) - result = pytester.runpytest_subprocess("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=5) From f99b67827484586bdbb055d06f64aa12ced62e24 Mon Sep 17 00:00:00 2001 From: "joao.faria" Date: Mon, 3 Nov 2025 19:32:46 -0300 Subject: [PATCH 2/5] test: add pytest config to isolated test directories - Add pytester.makeini() calls to ensure asyncio_default_fixture_loop_scope is properly configured in test directories --- tests/markers/test_invalid_arguments.py | 4 ++++ tests/test_asyncio_mark.py | 7 +++++++ tests/test_event_loop_fixture.py | 1 + tests/test_fixture_loop_scopes.py | 1 + 4 files changed, 13 insertions(+) diff --git a/tests/markers/test_invalid_arguments.py b/tests/markers/test_invalid_arguments.py index 82a68f08..2663ef95 100644 --- a/tests/markers/test_invalid_arguments.py +++ b/tests/markers/test_invalid_arguments.py @@ -8,6 +8,7 @@ def test_no_error_when_scope_passed_as_sole_keyword_argument( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -27,6 +28,7 @@ async def test_anything(): def test_error_when_scope_passed_as_positional_argument( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -48,6 +50,7 @@ async def test_anything(): def test_error_when_wrong_keyword_argument_is_passed( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -69,6 +72,7 @@ async def test_anything(): def test_error_when_additional_keyword_arguments_are_passed( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ diff --git a/tests/test_asyncio_mark.py b/tests/test_asyncio_mark.py index 283319c9..f4e88ba2 100644 --- a/tests/test_asyncio_mark.py +++ b/tests/test_asyncio_mark.py @@ -6,6 +6,7 @@ def test_asyncio_mark_on_sync_function_emits_warning(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -27,6 +28,7 @@ def test_a(): def test_asyncio_mark_on_async_generator_function_emits_warning_in_strict_mode( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -48,6 +50,7 @@ async def test_a(): def test_asyncio_mark_on_async_generator_function_emits_warning_in_auto_mode( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -66,6 +69,7 @@ async def test_a(): def test_asyncio_mark_on_async_generator_method_emits_warning_in_strict_mode( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -88,6 +92,7 @@ async def test_a(self): def test_asyncio_mark_on_async_generator_method_emits_warning_in_auto_mode( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -108,6 +113,7 @@ async def test_a(): def test_asyncio_mark_on_async_generator_staticmethod_emits_warning_in_strict_mode( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -131,6 +137,7 @@ async def test_a(): def test_asyncio_mark_on_async_generator_staticmethod_emits_warning_in_auto_mode( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ diff --git a/tests/test_event_loop_fixture.py b/tests/test_event_loop_fixture.py index c67b36d7..1b5711ed 100644 --- a/tests/test_event_loop_fixture.py +++ b/tests/test_event_loop_fixture.py @@ -6,6 +6,7 @@ def test_event_loop_fixture_respects_event_loop_policy(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makeconftest( dedent( """\ diff --git a/tests/test_fixture_loop_scopes.py b/tests/test_fixture_loop_scopes.py index 1fd29350..037b561a 100644 --- a/tests/test_fixture_loop_scopes.py +++ b/tests/test_fixture_loop_scopes.py @@ -13,6 +13,7 @@ def test_loop_scope_session_is_independent_of_fixture_scope( pytester: Pytester, fixture_scope: str, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( f"""\ From cfb3315bd88835f9bee5198e9bcd51dce5f67de3 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Tue, 4 Nov 2025 17:04:33 +0100 Subject: [PATCH 3/5] tests: Fix failing test by preventing warning conversion to error. --- tests/markers/test_function_scope.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/markers/test_function_scope.py b/tests/markers/test_function_scope.py index 16d45da5..0e28eae6 100644 --- a/tests/markers/test_function_scope.py +++ b/tests/markers/test_function_scope.py @@ -87,7 +87,7 @@ async def test_warns(): """ ) ) - result = pytester.runpytest("--asyncio-mode=strict", "--assert=plain") + result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") result.assert_outcomes(passed=1, warnings=1) result.stdout.fnmatch_lines("*DeprecationWarning*") From 93789376528ce99d649e12090ac479a54f12da05 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Tue, 4 Nov 2025 17:06:32 +0100 Subject: [PATCH 4/5] test: Remove obsolete test for the event_loop fixture. --- tests/test_event_loop_fixture.py | 51 -------------------------------- 1 file changed, 51 deletions(-) diff --git a/tests/test_event_loop_fixture.py b/tests/test_event_loop_fixture.py index 1b5711ed..5a03341f 100644 --- a/tests/test_event_loop_fixture.py +++ b/tests/test_event_loop_fixture.py @@ -5,57 +5,6 @@ from pytest import Pytester -def test_event_loop_fixture_respects_event_loop_policy(pytester: Pytester): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makeconftest( - dedent( - """\ - '''Defines and sets a custom event loop policy''' - import asyncio - from asyncio import DefaultEventLoopPolicy, SelectorEventLoop - - class TestEventLoop(SelectorEventLoop): - pass - - class TestEventLoopPolicy(DefaultEventLoopPolicy): - def new_event_loop(self): - return TestEventLoop() - - # This statement represents a code which sets a custom event loop policy - asyncio.set_event_loop_policy(TestEventLoopPolicy()) - """ - ) - ) - pytester.makepyfile( - dedent( - """\ - '''Tests that any externally provided event loop policy remains unaltered''' - import asyncio - - import pytest - - - @pytest.mark.asyncio - async def test_uses_loop_provided_by_custom_policy(): - '''Asserts that test cases use the event loop - provided by the custom event loop policy''' - assert type(asyncio.get_event_loop()).__name__ == "TestEventLoop" - - - @pytest.mark.asyncio - async def test_custom_policy_is_not_overwritten(): - ''' - Asserts that any custom event loop policy stays the same - across test cases. - ''' - assert type(asyncio.get_event_loop()).__name__ == "TestEventLoop" - """ - ) - ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) - - def test_event_loop_fixture_handles_unclosed_async_gen( pytester: Pytester, ): From 25801be1837b60fa7d60f8c7face846680a87287 Mon Sep 17 00:00:00 2001 From: "joao.faria" Date: Tue, 4 Nov 2025 22:45:47 -0300 Subject: [PATCH 5/5] tests: handle Python 3.14 DefaultEventLoopPolicy deprecation warnings --- tests/markers/test_class_scope.py | 23 +++++++++++++++++++---- tests/markers/test_function_scope.py | 23 +++++++++++++++++++---- tests/markers/test_module_scope.py | 23 +++++++++++++++++++---- tests/markers/test_package_scope.py | 23 +++++++++++++++++++---- tests/markers/test_session_scope.py | 23 +++++++++++++++++++---- 5 files changed, 95 insertions(+), 20 deletions(-) diff --git a/tests/markers/test_class_scope.py b/tests/markers/test_class_scope.py index 300da183..15a8fdc4 100644 --- a/tests/markers/test_class_scope.py +++ b/tests/markers/test_class_scope.py @@ -3,6 +3,7 @@ from __future__ import annotations import asyncio +import sys from textwrap import dedent import pytest @@ -143,8 +144,15 @@ async def test_does_not_use_custom_event_loop_policy(): """ ) ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=2, warnings=3) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=2) def test_asyncio_mark_respects_parametrized_loop_policies( @@ -175,8 +183,15 @@ async def test_parametrized_loop(self, request): """ ) ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=2, warnings=2) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=2) def test_asyncio_mark_provides_class_scoped_loop_to_fixtures( diff --git a/tests/markers/test_function_scope.py b/tests/markers/test_function_scope.py index 0e28eae6..97ea08e6 100644 --- a/tests/markers/test_function_scope.py +++ b/tests/markers/test_function_scope.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys from textwrap import dedent from pytest import Pytester @@ -119,8 +120,15 @@ async def test_uses_custom_event_loop_policy(): """ ), ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=1) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=1, warnings=2) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=1) def test_asyncio_mark_respects_parametrized_loop_policies( @@ -157,8 +165,15 @@ async def test_parametrized_loop(): """ ) ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=2, warnings=3) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=2) def test_asyncio_mark_provides_function_scoped_loop_to_fixtures( diff --git a/tests/markers/test_module_scope.py b/tests/markers/test_module_scope.py index 5b490b26..633e6121 100644 --- a/tests/markers/test_module_scope.py +++ b/tests/markers/test_module_scope.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys from textwrap import dedent from pytest import Pytester @@ -87,8 +88,15 @@ async def test_does_not_use_custom_event_loop_policy(): """ ), ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=2, warnings=3) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=2) def test_asyncio_mark_respects_parametrized_loop_policies( @@ -119,8 +127,15 @@ async def test_parametrized_loop(): """ ) ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=2, warnings=2) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=2) def test_asyncio_mark_provides_module_scoped_loop_to_fixtures( diff --git a/tests/markers/test_package_scope.py b/tests/markers/test_package_scope.py index 26fcd23f..76bd85ea 100644 --- a/tests/markers/test_package_scope.py +++ b/tests/markers/test_package_scope.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys from textwrap import dedent from pytest import Pytester @@ -127,8 +128,15 @@ async def test_also_uses_custom_event_loop_policy(): """ ), ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=2, warnings=3) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=2) def test_asyncio_mark_respects_parametrized_loop_policies( @@ -160,8 +168,15 @@ async def test_parametrized_loop(): """ ), ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=2, warnings=2) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=2) def test_asyncio_mark_provides_package_scoped_loop_to_fixtures( diff --git a/tests/markers/test_session_scope.py b/tests/markers/test_session_scope.py index b8d110f1..88eec6c3 100644 --- a/tests/markers/test_session_scope.py +++ b/tests/markers/test_session_scope.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys from textwrap import dedent from pytest import Pytester @@ -128,8 +129,15 @@ async def test_also_uses_custom_event_loop_policy(): """ ), ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=2, warnings=3) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=2) def test_asyncio_mark_respects_parametrized_loop_policies( @@ -161,8 +169,15 @@ async def test_parametrized_loop(): """ ), ) - result = pytester.runpytest("--asyncio-mode=strict") - result.assert_outcomes(passed=2) + pytest_args = ["--asyncio-mode=strict"] + if sys.version_info >= (3, 14): + pytest_args.extend(["-W", "default"]) + result = pytester.runpytest(*pytest_args) + if sys.version_info >= (3, 14): + result.assert_outcomes(passed=2, warnings=2) + result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") + else: + result.assert_outcomes(passed=2) def test_asyncio_mark_provides_session_scoped_loop_to_fixtures(