From 6ec9829776e336f8bd6d4e39e94da62bb37b4031 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 08:58:53 +0200 Subject: [PATCH 01/18] refactor: Set default asyncio event loop for fixtures in setup.cfg --- .../class_scoped_loop_with_fixture_strict_mode_example.py | 2 +- setup.cfg | 1 + tests/async_fixtures/test_async_fixtures_with_finalizer.py | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/reference/markers/class_scoped_loop_with_fixture_strict_mode_example.py b/docs/reference/markers/class_scoped_loop_with_fixture_strict_mode_example.py index 239f3968..6fff0af8 100644 --- a/docs/reference/markers/class_scoped_loop_with_fixture_strict_mode_example.py +++ b/docs/reference/markers/class_scoped_loop_with_fixture_strict_mode_example.py @@ -9,7 +9,7 @@ class TestClassScopedLoop: loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="class") + @pytest_asyncio.fixture(loop_scope="class") async def my_fixture(self): TestClassScopedLoop.loop = asyncio.get_running_loop() diff --git a/setup.cfg b/setup.cfg index ac2f2adc..00c6bdd4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -67,6 +67,7 @@ python_files = test_*.py *_example.py addopts = -rsx --tb=short testpaths = docs tests asyncio_mode = auto +asyncio_default_fixture_loop_scope = function junit_family=xunit2 filterwarnings = error diff --git a/tests/async_fixtures/test_async_fixtures_with_finalizer.py b/tests/async_fixtures/test_async_fixtures_with_finalizer.py index bc6826bb..8efc8fc4 100644 --- a/tests/async_fixtures/test_async_fixtures_with_finalizer.py +++ b/tests/async_fixtures/test_async_fixtures_with_finalizer.py @@ -3,6 +3,8 @@ import pytest +import pytest_asyncio + @pytest.mark.asyncio(loop_scope="module") async def test_module_with_event_loop_finalizer(port_with_event_loop_finalizer): @@ -25,7 +27,7 @@ def event_loop(): loop.close() -@pytest.fixture(scope="module") +@pytest_asyncio.fixture(loop_scope="module", scope="module") async def port_with_event_loop_finalizer(request): def port_finalizer(finalizer): async def port_afinalizer(): @@ -40,7 +42,7 @@ async def port_afinalizer(): return True -@pytest.fixture(scope="module") +@pytest_asyncio.fixture(loop_scope="module", scope="module") async def port_with_get_event_loop_finalizer(request): def port_finalizer(finalizer): async def port_afinalizer(): From 81c9ad35011b91953cb669b2a80967a04a1b9aed Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 09:37:27 +0200 Subject: [PATCH 02/18] refactor: Addressed warning about missing default fixture scope configuration in tests/async_fixtures/test_shared_module_fixture.py --- tests/async_fixtures/test_shared_module_fixture.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/async_fixtures/test_shared_module_fixture.py b/tests/async_fixtures/test_shared_module_fixture.py index ff1cb62b..9b0ad540 100644 --- a/tests/async_fixtures/test_shared_module_fixture.py +++ b/tests/async_fixtures/test_shared_module_fixture.py @@ -4,12 +4,13 @@ def test_asyncio_mark_provides_package_scoped_loop_strict_mode(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", conftest=dedent( """\ import pytest_asyncio - @pytest_asyncio.fixture(scope="module") + @pytest_asyncio.fixture(loop_scope="module", scope="module") async def async_shared_module_fixture(): return True """ From f990587bb5bac7618da787617f09a9ddd9547285 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 09:42:06 +0200 Subject: [PATCH 03/18] refactor: Addressed warning about missing default fixture loop scope in Hypothesis tests. --- tests/hypothesis/test_base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/hypothesis/test_base.py b/tests/hypothesis/test_base.py index 2d2171bd..176c9aee 100644 --- a/tests/hypothesis/test_base.py +++ b/tests/hypothesis/test_base.py @@ -10,6 +10,7 @@ def test_hypothesis_given_decorator_before_asyncio_mark(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -42,6 +43,7 @@ async def test_mark_and_parametrize(x, y): def test_can_use_explicit_event_loop_fixture(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = module") pytester.makepyfile( dedent( """\ @@ -78,6 +80,7 @@ async def test_explicit_fixture_request(event_loop, n): def test_async_auto_marked(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -100,6 +103,7 @@ async def test_hypothesis(n: int): def test_sync_not_auto_marked(pytester: Pytester): """Assert that synchronous Hypothesis functions are not marked with asyncio""" + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ From f548101e5de9357d8d262740d940a9ba729fdfda Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 09:52:23 +0200 Subject: [PATCH 04/18] refactor: Addressed warnings about missing default fixture loop in tests/markers/test_class_scope.py. --- tests/markers/test_class_scope.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/markers/test_class_scope.py b/tests/markers/test_class_scope.py index baac5869..edce31f6 100644 --- a/tests/markers/test_class_scope.py +++ b/tests/markers/test_class_scope.py @@ -30,6 +30,7 @@ def sample_fixture(): def test_asyncio_mark_provides_class_scoped_loop_when_applied_to_functions( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -56,6 +57,7 @@ async def test_this_runs_in_same_loop(self): def test_asyncio_mark_provides_class_scoped_loop_when_applied_to_class( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -81,6 +83,7 @@ async def test_this_runs_in_same_loop(self): def test_asyncio_mark_raises_when_class_scoped_is_request_without_class( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -101,6 +104,7 @@ async def test_has_no_surrounding_class(): def test_asyncio_mark_is_inherited_to_subclasses(pytester: pytest.Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -129,6 +133,7 @@ async def test_this_runs_in_same_loop(self): def test_asyncio_mark_respects_the_loop_policy( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -166,6 +171,7 @@ async def test_does_not_use_custom_event_loop_policy(): def test_asyncio_mark_respects_parametrized_loop_policies( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -197,6 +203,7 @@ async def test_parametrized_loop(self, request): def test_asyncio_mark_provides_class_scoped_loop_to_fixtures( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -226,6 +233,7 @@ async def test_runs_is_same_loop_as_fixture(self, my_fixture): def test_asyncio_mark_allows_combining_class_scoped_fixture_with_function_scoped_test( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -237,7 +245,7 @@ def test_asyncio_mark_allows_combining_class_scoped_fixture_with_function_scoped loop: asyncio.AbstractEventLoop class TestMixedScopes: - @pytest_asyncio.fixture(scope="class") + @pytest_asyncio.fixture(loop_scope="class", scope="class") async def async_fixture(self): global loop loop = asyncio.get_running_loop() @@ -257,6 +265,7 @@ async def test_runs_in_different_loop_as_fixture(self, async_fixture): def test_asyncio_mark_handles_missing_event_loop_triggered_by_fixture( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -292,6 +301,7 @@ async def test_does_not_fail(self, sets_event_loop_to_none, n): def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_being_set( pytester: pytest.Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ From 40fb982cfda6e67bcd18fbc447354a8599bed1be Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 09:57:03 +0200 Subject: [PATCH 05/18] refactor: Addressed warnings about missing default fixture loop in tests/markers/test_function_scope.py. --- tests/markers/test_function_scope.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/markers/test_function_scope.py b/tests/markers/test_function_scope.py index 81260006..75487b5d 100644 --- a/tests/markers/test_function_scope.py +++ b/tests/markers/test_function_scope.py @@ -4,6 +4,7 @@ def test_asyncio_mark_provides_function_scoped_loop_strict_mode(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -29,6 +30,7 @@ async def test_does_not_run_in_same_loop(): def test_loop_scope_function_provides_function_scoped_event_loop(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -54,6 +56,7 @@ async def test_does_not_run_in_same_loop(): def test_raises_when_scope_and_loop_scope_arguments_are_present(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -70,6 +73,7 @@ async def test_raises(): def test_warns_when_scope_argument_is_present(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -89,6 +93,7 @@ async def test_warns(): def test_function_scope_supports_explicit_event_loop_fixture_request( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -111,6 +116,7 @@ async def test_remember_loop(event_loop): def test_asyncio_mark_respects_the_loop_policy( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -141,6 +147,7 @@ async def test_uses_custom_event_loop_policy(): def test_asyncio_mark_respects_parametrized_loop_policies( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -178,6 +185,7 @@ async def test_parametrized_loop(): def test_asyncio_mark_provides_function_scoped_loop_to_fixtures( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -208,6 +216,7 @@ async def test_runs_is_same_loop_as_fixture(my_fixture): def test_asyncio_mark_handles_missing_event_loop_triggered_by_fixture( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -242,6 +251,7 @@ async def test_does_not_fail(sets_event_loop_to_none, n): def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_being_set( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -260,6 +270,7 @@ async def test_anything(): def test_asyncio_mark_does_not_duplicate_other_marks_in_auto_mode( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makeconftest( dedent( """\ From 0a32b2726a27e980ad5f47741ad3edffa8fc7b60 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 10:05:20 +0200 Subject: [PATCH 06/18] refactor: Addressed warnings about missing default fixture loop scope in tests/markers/test_module_scope.py. --- tests/markers/test_module_scope.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/markers/test_module_scope.py b/tests/markers/test_module_scope.py index 5280ed7e..12515f23 100644 --- a/tests/markers/test_module_scope.py +++ b/tests/markers/test_module_scope.py @@ -4,6 +4,7 @@ def test_asyncio_mark_works_on_module_level(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -56,6 +57,7 @@ def sample_fixture(): def test_asyncio_mark_provides_module_scoped_loop_strict_mode(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -88,6 +90,7 @@ async def test_this_runs_in_same_loop(self): def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -109,6 +112,7 @@ async def test_remember_loop(event_loop): def test_asyncio_mark_respects_the_loop_policy( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", custom_policy=dedent( @@ -163,6 +167,7 @@ async def test_does_not_use_custom_event_loop_policy(): def test_asyncio_mark_respects_parametrized_loop_policies( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -194,6 +199,7 @@ async def test_parametrized_loop(): def test_asyncio_mark_provides_module_scoped_loop_to_fixtures( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -206,7 +212,7 @@ def test_asyncio_mark_provides_module_scoped_loop_to_fixtures( loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="module") + @pytest_asyncio.fixture(loop_scope="module", scope="module") async def my_fixture(): global loop loop = asyncio.get_running_loop() @@ -224,6 +230,7 @@ async def test_runs_is_same_loop_as_fixture(my_fixture): def test_asyncio_mark_allows_combining_module_scoped_fixture_with_class_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -234,7 +241,7 @@ def test_asyncio_mark_allows_combining_module_scoped_fixture_with_class_scoped_t loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="module") + @pytest_asyncio.fixture(loop_scope="module", scope="module") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -255,6 +262,7 @@ async def test_runs_in_different_loop_as_fixture(self, async_fixture): def test_asyncio_mark_allows_combining_module_scoped_fixture_with_function_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_mixed_scopes=dedent( @@ -266,7 +274,7 @@ def test_asyncio_mark_allows_combining_module_scoped_fixture_with_function_scope loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="module") + @pytest_asyncio.fixture(loop_scope="module", scope="module") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -285,6 +293,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture): def test_allows_combining_module_scoped_asyncgen_fixture_with_function_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -295,7 +304,7 @@ def test_allows_combining_module_scoped_asyncgen_fixture_with_function_scoped_te loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="module") + @pytest_asyncio.fixture(loop_scope="module", scope="module") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -315,6 +324,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture): def test_asyncio_mark_handles_missing_event_loop_triggered_by_fixture( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -349,6 +359,7 @@ async def test_does_not_fail(sets_event_loop_to_none, n): def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_being_set( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ From 810dad16c2bbc4782a3536c18739eef4a2e59ff0 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 10:10:42 +0200 Subject: [PATCH 07/18] refactor: Addressed warnings about missing default fixture loop scope in tests/markers/test_package_scope.py. --- tests/markers/test_package_scope.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/markers/test_package_scope.py b/tests/markers/test_package_scope.py index 849967e8..bd3e4ac7 100644 --- a/tests/markers/test_package_scope.py +++ b/tests/markers/test_package_scope.py @@ -6,6 +6,7 @@ def test_asyncio_mark_provides_package_scoped_loop_strict_mode(pytester: Pytester): package_name = pytester.path.name subpackage_name = "subpkg" + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", shared_module=dedent( @@ -69,6 +70,7 @@ async def test_subpackage_runs_in_different_loop(): def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_raises=dedent( @@ -90,6 +92,7 @@ async def test_remember_loop(event_loop): def test_asyncio_mark_respects_the_loop_policy( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", conftest=dedent( @@ -151,6 +154,7 @@ async def test_also_uses_custom_event_loop_policy(): def test_asyncio_mark_respects_parametrized_loop_policies( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_parametrization=dedent( @@ -183,6 +187,7 @@ async def test_parametrized_loop(): def test_asyncio_mark_provides_package_scoped_loop_to_fixtures( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") package_name = pytester.path.name pytester.makepyfile( __init__="", @@ -194,7 +199,7 @@ def test_asyncio_mark_provides_package_scoped_loop_to_fixtures( from {package_name} import shared_module - @pytest_asyncio.fixture(scope="package") + @pytest_asyncio.fixture(loop_scope="package", scope="package") async def my_fixture(): shared_module.loop = asyncio.get_running_loop() """ @@ -229,6 +234,7 @@ async def test_runs_in_same_loop_as_fixture(my_fixture): def test_asyncio_mark_allows_combining_package_scoped_fixture_with_module_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_mixed_scopes=dedent( @@ -240,7 +246,7 @@ def test_asyncio_mark_allows_combining_package_scoped_fixture_with_module_scoped loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="package") + @pytest_asyncio.fixture(loop_scope="package", scope="package") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -259,6 +265,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture): def test_asyncio_mark_allows_combining_package_scoped_fixture_with_class_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_mixed_scopes=dedent( @@ -270,7 +277,7 @@ def test_asyncio_mark_allows_combining_package_scoped_fixture_with_class_scoped_ loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="package") + @pytest_asyncio.fixture(loop_scope="package", scope="package") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -290,6 +297,7 @@ async def test_runs_in_different_loop_as_fixture(self, async_fixture): def test_asyncio_mark_allows_combining_package_scoped_fixture_with_function_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_mixed_scopes=dedent( @@ -301,7 +309,7 @@ def test_asyncio_mark_allows_combining_package_scoped_fixture_with_function_scop loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="package") + @pytest_asyncio.fixture(loop_scope="package", scope="package") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -320,6 +328,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture): def test_asyncio_mark_handles_missing_event_loop_triggered_by_fixture( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_loop_is_none=dedent( @@ -355,6 +364,7 @@ async def test_does_not_fail(sets_event_loop_to_none, n): def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_being_set( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_module=dedent( From 838f573871ae5f5faa1968af81cdad609f1631fd Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 10:17:55 +0200 Subject: [PATCH 08/18] refactor: Addressed warnings about missing default fixture loop scope in tests/markers/test_session_scope.py. --- tests/markers/test_session_scope.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/markers/test_session_scope.py b/tests/markers/test_session_scope.py index 7900ef48..3bc38a4f 100644 --- a/tests/markers/test_session_scope.py +++ b/tests/markers/test_session_scope.py @@ -5,6 +5,7 @@ def test_asyncio_mark_provides_session_scoped_loop_strict_mode(pytester: Pytester): package_name = pytester.path.name + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", shared_module=dedent( @@ -70,6 +71,7 @@ async def test_subpackage_runs_in_same_loop(): def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_raises=dedent( @@ -91,6 +93,7 @@ async def test_remember_loop(event_loop): def test_asyncio_mark_respects_the_loop_policy( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", conftest=dedent( @@ -152,6 +155,7 @@ async def test_also_uses_custom_event_loop_policy(): def test_asyncio_mark_respects_parametrized_loop_policies( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_parametrization=dedent( @@ -185,6 +189,7 @@ def test_asyncio_mark_provides_session_scoped_loop_to_fixtures( pytester: Pytester, ): package_name = pytester.path.name + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", conftest=dedent( @@ -195,7 +200,7 @@ def test_asyncio_mark_provides_session_scoped_loop_to_fixtures( from {package_name} import shared_module - @pytest_asyncio.fixture(scope="session") + @pytest_asyncio.fixture(loop_scope="session", scope="session") async def my_fixture(): shared_module.loop = asyncio.get_running_loop() """ @@ -234,6 +239,7 @@ async def test_runs_in_same_loop_as_fixture(my_fixture): def test_asyncio_mark_allows_combining_session_scoped_fixture_with_package_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_mixed_scopes=dedent( @@ -245,7 +251,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_package_scope loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="session") + @pytest_asyncio.fixture(loop_scope="session", scope="session") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -264,6 +270,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture): def test_asyncio_mark_allows_combining_session_scoped_fixture_with_module_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_mixed_scopes=dedent( @@ -275,7 +282,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_module_scoped loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="session") + @pytest_asyncio.fixture(loop_scope="session", scope="session") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -294,6 +301,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture): def test_asyncio_mark_allows_combining_session_scoped_fixture_with_class_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_mixed_scopes=dedent( @@ -305,7 +313,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_class_scoped_ loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="session") + @pytest_asyncio.fixture(loop_scope="session", scope="session") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -325,6 +333,7 @@ async def test_runs_in_different_loop_as_fixture(self, async_fixture): def test_asyncio_mark_allows_combining_session_scoped_fixture_with_function_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_mixed_scopes=dedent( @@ -336,7 +345,7 @@ def test_asyncio_mark_allows_combining_session_scoped_fixture_with_function_scop loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="session") + @pytest_asyncio.fixture(loop_scope="session", scope="session") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -355,6 +364,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture): def test_allows_combining_session_scoped_asyncgen_fixture_with_function_scoped_test( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_mixed_scopes=dedent( @@ -366,7 +376,7 @@ def test_allows_combining_session_scoped_asyncgen_fixture_with_function_scoped_t loop: asyncio.AbstractEventLoop - @pytest_asyncio.fixture(scope="session") + @pytest_asyncio.fixture(loop_scope="session", scope="session") async def async_fixture(): global loop loop = asyncio.get_running_loop() @@ -386,6 +396,7 @@ async def test_runs_in_different_loop_as_fixture(async_fixture): def test_asyncio_mark_handles_missing_event_loop_triggered_by_fixture( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -420,6 +431,7 @@ async def test_does_not_fail(sets_event_loop_to_none, n): def test_standalone_test_does_not_trigger_warning_about_no_current_event_loop_being_set( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ From 58b934fcd75c2a2cdfa82bed0209f033c47ca745 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 13:00:20 +0200 Subject: [PATCH 09/18] refactor: test_auto_mode uses pytester, instead of testdir. --- tests/modes/test_auto_mode.py | 40 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/modes/test_auto_mode.py b/tests/modes/test_auto_mode.py index fc4d2df0..8baa31ea 100644 --- a/tests/modes/test_auto_mode.py +++ b/tests/modes/test_auto_mode.py @@ -1,8 +1,10 @@ from textwrap import dedent +from pytest import Pytester -def test_auto_mode_cmdline(testdir): - testdir.makepyfile( + +def test_auto_mode_cmdline(pytester: Pytester): + pytester.makepyfile( dedent( """\ import asyncio @@ -15,12 +17,12 @@ async def test_a(): """ ) ) - result = testdir.runpytest("--asyncio-mode=auto") + result = pytester.runpytest("--asyncio-mode=auto") result.assert_outcomes(passed=1) -def test_auto_mode_cfg(testdir): - testdir.makepyfile( +def test_auto_mode_cfg(pytester: Pytester): + pytester.makepyfile( dedent( """\ import asyncio @@ -33,13 +35,13 @@ async def test_a(): """ ) ) - testdir.makefile(".ini", pytest="[pytest]\nasyncio_mode = auto\n") - result = testdir.runpytest() + pytester.makefile(".ini", pytest="[pytest]\nasyncio_mode = auto\n") + result = pytester.runpytest() result.assert_outcomes(passed=1) -def test_auto_mode_async_fixture(testdir): - testdir.makepyfile( +def test_auto_mode_async_fixture(pytester: Pytester): + pytester.makepyfile( dedent( """\ import asyncio @@ -58,12 +60,12 @@ async def test_a(fixture_a): """ ) ) - result = testdir.runpytest("--asyncio-mode=auto") + result = pytester.runpytest("--asyncio-mode=auto") result.assert_outcomes(passed=1) -def test_auto_mode_method_fixture(testdir): - testdir.makepyfile( +def test_auto_mode_method_fixture(pytester: Pytester): + pytester.makepyfile( dedent( """\ import asyncio @@ -85,12 +87,12 @@ async def test_a(self, fixture_a): """ ) ) - result = testdir.runpytest("--asyncio-mode=auto") + result = pytester.runpytest("--asyncio-mode=auto") result.assert_outcomes(passed=1) -def test_auto_mode_static_method(testdir): - testdir.makepyfile( +def test_auto_mode_static_method(pytester: Pytester): + pytester.makepyfile( dedent( """\ import asyncio @@ -106,12 +108,12 @@ async def test_a(): """ ) ) - result = testdir.runpytest("--asyncio-mode=auto") + result = pytester.runpytest("--asyncio-mode=auto") result.assert_outcomes(passed=1) -def test_auto_mode_static_method_fixture(testdir): - testdir.makepyfile( +def test_auto_mode_static_method_fixture(pytester: Pytester): + pytester.makepyfile( dedent( """\ import asyncio @@ -135,5 +137,5 @@ async def test_a(fixture_a): """ ) ) - result = testdir.runpytest("--asyncio-mode=auto") + result = pytester.runpytest("--asyncio-mode=auto") result.assert_outcomes(passed=1) From 60064565d581a43846fb0054b5a36fd03e71d54d Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 13:09:16 +0200 Subject: [PATCH 10/18] refactor: Addressed warnings about missing default fixture loop scope in tests/modes/test_auto_mode.py. --- tests/modes/test_auto_mode.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/modes/test_auto_mode.py b/tests/modes/test_auto_mode.py index 8baa31ea..f41c9d1a 100644 --- a/tests/modes/test_auto_mode.py +++ b/tests/modes/test_auto_mode.py @@ -4,6 +4,7 @@ def test_auto_mode_cmdline(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -22,6 +23,15 @@ async def test_a(): def test_auto_mode_cfg(pytester: Pytester): + pytester.makeini( + dedent( + """\ + [pytest] + asyncio_default_fixture_loop_scope = function + asyncio_mode = auto + """ + ) + ) pytester.makepyfile( dedent( """\ @@ -35,12 +45,12 @@ async def test_a(): """ ) ) - pytester.makefile(".ini", pytest="[pytest]\nasyncio_mode = auto\n") - result = pytester.runpytest() + result = pytester.runpytest("--asyncio-mode=auto") result.assert_outcomes(passed=1) def test_auto_mode_async_fixture(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -65,6 +75,7 @@ async def test_a(fixture_a): def test_auto_mode_method_fixture(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -92,6 +103,7 @@ async def test_a(self, fixture_a): def test_auto_mode_static_method(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -113,6 +125,7 @@ async def test_a(): def test_auto_mode_static_method_fixture(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ From 9e9d036bf77f70195c527d8de25e9e9d57a0a1a1 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 13:13:22 +0200 Subject: [PATCH 11/18] refactor: Replaced use of testdir with pytester in test_strict_mode. --- tests/modes/test_strict_mode.py | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/modes/test_strict_mode.py b/tests/modes/test_strict_mode.py index 220410be..0e337cae 100644 --- a/tests/modes/test_strict_mode.py +++ b/tests/modes/test_strict_mode.py @@ -1,8 +1,10 @@ from textwrap import dedent +from pytest import Pytester -def test_strict_mode_cmdline(testdir): - testdir.makepyfile( + +def test_strict_mode_cmdline(pytester: Pytester): + pytester.makepyfile( dedent( """\ import asyncio @@ -16,12 +18,12 @@ async def test_a(): """ ) ) - result = testdir.runpytest("--asyncio-mode=strict") + result = pytester.runpytest("--asyncio-mode=strict") result.assert_outcomes(passed=1) -def test_strict_mode_cfg(testdir): - testdir.makepyfile( +def test_strict_mode_cfg(pytester: Pytester): + pytester.makepyfile( dedent( """\ import asyncio @@ -35,13 +37,13 @@ async def test_a(): """ ) ) - testdir.makefile(".ini", pytest="[pytest]\nasyncio_mode = strict\n") - result = testdir.runpytest() + pytester.makefile(".ini", pytest="[pytest]\nasyncio_mode = strict\n") + result = pytester.runpytest() result.assert_outcomes(passed=1) -def test_strict_mode_method_fixture(testdir): - testdir.makepyfile( +def test_strict_mode_method_fixture(pytester: Pytester): + pytester.makepyfile( dedent( """\ import asyncio @@ -64,12 +66,12 @@ async def test_a(self, fixture_a): """ ) ) - result = testdir.runpytest("--asyncio-mode=auto") + result = pytester.runpytest("--asyncio-mode=auto") result.assert_outcomes(passed=1) -def test_strict_mode_ignores_unmarked_coroutine(testdir): - testdir.makepyfile( +def test_strict_mode_ignores_unmarked_coroutine(pytester: Pytester): + pytester.makepyfile( dedent( """\ import pytest @@ -79,13 +81,13 @@ async def test_anything(): """ ) ) - result = testdir.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") result.assert_outcomes(skipped=1, warnings=1) result.stdout.fnmatch_lines(["*async def functions are not natively supported*"]) -def test_strict_mode_ignores_unmarked_fixture(testdir): - testdir.makepyfile( +def test_strict_mode_ignores_unmarked_fixture(pytester: Pytester): + pytester.makepyfile( dedent( """\ import pytest @@ -100,7 +102,7 @@ async def test_anything(any_fixture): """ ) ) - result = testdir.runpytest_subprocess("--asyncio-mode=strict", "-W default") + result = pytester.runpytest_subprocess("--asyncio-mode=strict", "-W default") result.assert_outcomes(skipped=1, warnings=2) result.stdout.fnmatch_lines( [ From 9556f8bd2293842b6b9dff78585e9115aaa3bb3b Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 13:17:56 +0200 Subject: [PATCH 12/18] refactor: Addressed warnings about missing default fixture loop scope in test_strict_mode. --- tests/modes/test_strict_mode.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/modes/test_strict_mode.py b/tests/modes/test_strict_mode.py index 0e337cae..b8232d05 100644 --- a/tests/modes/test_strict_mode.py +++ b/tests/modes/test_strict_mode.py @@ -4,6 +4,7 @@ def test_strict_mode_cmdline(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -23,6 +24,15 @@ async def test_a(): def test_strict_mode_cfg(pytester: Pytester): + pytester.makeini( + dedent( + """\ + [pytest] + asyncio_default_fixture_loop_scope = function + asyncio_mode = strict + """ + ) + ) pytester.makepyfile( dedent( """\ @@ -37,12 +47,12 @@ async def test_a(): """ ) ) - pytester.makefile(".ini", pytest="[pytest]\nasyncio_mode = strict\n") result = pytester.runpytest() result.assert_outcomes(passed=1) def test_strict_mode_method_fixture(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -71,6 +81,7 @@ async def test_a(self, fixture_a): def test_strict_mode_ignores_unmarked_coroutine(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -87,6 +98,7 @@ async def test_anything(): def test_strict_mode_ignores_unmarked_fixture(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ From 9eb9cecfd2f19556069eb34180d35d51eda80ed9 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 13:23:48 +0200 Subject: [PATCH 13/18] refactor: Addressed warnings about missing default fixture loop scope in tests/test_asyncio_fixture.py. --- tests/test_asyncio_fixture.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_asyncio_fixture.py b/tests/test_asyncio_fixture.py index 2577cba0..4bdabce2 100644 --- a/tests/test_asyncio_fixture.py +++ b/tests/test_asyncio_fixture.py @@ -2,6 +2,7 @@ from textwrap import dedent import pytest +from pytest import Pytester import pytest_asyncio @@ -43,8 +44,9 @@ async def test_fixture_with_params(fixture_with_params): @pytest.mark.parametrize("mode", ("auto", "strict")) -def test_sync_function_uses_async_fixture(testdir, mode): - testdir.makepyfile( +def test_sync_function_uses_async_fixture(pytester: Pytester, mode): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") + pytester.makepyfile( dedent( """\ import pytest_asyncio @@ -60,5 +62,5 @@ def test_sync_function_uses_async_fixture(always_true): """ ) ) - result = testdir.runpytest(f"--asyncio-mode={mode}") + result = pytester.runpytest(f"--asyncio-mode={mode}") result.assert_outcomes(passed=1) From 5d256b8b38cb56f55318b252f56be9a598fc4b3e Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Fri, 23 Aug 2024 13:26:47 +0200 Subject: [PATCH 14/18] refactor: Addressed warnings about missing default fixture loop scope in test_doctest. --- tests/test_doctest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_doctest.py b/tests/test_doctest.py index 5b79619a..3795a4d7 100644 --- a/tests/test_doctest.py +++ b/tests/test_doctest.py @@ -4,6 +4,7 @@ def test_plugin_does_not_interfere_with_doctest_collection(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( '''\ @@ -20,6 +21,7 @@ def any_function(): def test_plugin_does_not_interfere_with_doctest_textfile_collection(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makefile(".txt", "") # collected as DoctestTextfile pytester.makepyfile( __init__="", From 440dccdf590e6b14084806ab1cce70bc69cb028d Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Sat, 24 Aug 2024 21:57:32 +0200 Subject: [PATCH 15/18] refactor: Addressed warning about missing default fixture loop scope in tests/test_event_loop_fixture_finalizer.py. --- tests/test_event_loop_fixture_finalizer.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_event_loop_fixture_finalizer.py b/tests/test_event_loop_fixture_finalizer.py index ae260261..4306c33d 100644 --- a/tests/test_event_loop_fixture_finalizer.py +++ b/tests/test_event_loop_fixture_finalizer.py @@ -4,6 +4,7 @@ def test_event_loop_fixture_finalizer_returns_fresh_loop_after_test(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -36,6 +37,7 @@ def test_2(): def test_event_loop_fixture_finalizer_handles_loop_set_to_none_sync( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -53,6 +55,7 @@ def test_sync(event_loop): def test_event_loop_fixture_finalizer_handles_loop_set_to_none_async_without_fixture( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -72,6 +75,7 @@ async def test_async_without_explicit_fixture_request(): def test_event_loop_fixture_finalizer_handles_loop_set_to_none_async_with_fixture( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -94,6 +98,7 @@ async def test_async_with_explicit_fixture_request(event_loop): def test_event_loop_fixture_finalizer_raises_warning_when_fixture_leaves_loop_unclosed( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -121,6 +126,7 @@ async def test_ends_with_unclosed_loop(): def test_event_loop_fixture_finalizer_raises_warning_when_test_leaves_loop_unclosed( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ From 474a6134cbfad540979398908a8c54857198b86e Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Sat, 24 Aug 2024 21:59:55 +0200 Subject: [PATCH 16/18] refactor: Addressed warnings about missing default fixture loop scope in tests/test_explicit_event_loop_fixture_request.py. --- tests/test_explicit_event_loop_fixture_request.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_explicit_event_loop_fixture_request.py b/tests/test_explicit_event_loop_fixture_request.py index e09893fa..382fbf7c 100644 --- a/tests/test_explicit_event_loop_fixture_request.py +++ b/tests/test_explicit_event_loop_fixture_request.py @@ -6,6 +6,7 @@ def test_emit_warning_when_event_loop_is_explicitly_requested_in_coroutine( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -27,6 +28,7 @@ async def test_coroutine_emits_warning(event_loop): def test_emit_warning_when_event_loop_is_explicitly_requested_in_coroutine_method( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -49,6 +51,7 @@ async def test_coroutine_emits_warning(self, event_loop): def test_emit_warning_when_event_loop_is_explicitly_requested_in_coroutine_staticmethod( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -72,6 +75,7 @@ async def test_coroutine_emits_warning(event_loop): def test_emit_warning_when_event_loop_is_explicitly_requested_in_coroutine_fixture( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -98,6 +102,7 @@ async def test_uses_fixture(emits_warning): def test_emit_warning_when_event_loop_is_explicitly_requested_in_async_gen_fixture( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -124,6 +129,7 @@ async def test_uses_fixture(emits_warning): def test_does_not_emit_warning_when_event_loop_is_explicitly_requested_in_sync_function( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -141,6 +147,7 @@ def test_uses_fixture(event_loop): def test_does_not_emit_warning_when_event_loop_is_explicitly_requested_in_sync_fixture( pytester: Pytester, ): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ From 63f1400840140dc01acc8bab1e6c276247c06b82 Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Sat, 24 Aug 2024 22:01:36 +0200 Subject: [PATCH 17/18] refactor: Addressed warnings about missing default fixture loop scope in tests/test_import.py. --- tests/test_import.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_import.py b/tests/test_import.py index 9912ae0c..f1bf3caf 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -4,6 +4,7 @@ def test_import_warning_does_not_cause_internal_error(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -19,6 +20,7 @@ async def test_errors_out(): def test_import_warning_in_package_does_not_cause_internal_error(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__=dedent( """\ @@ -37,6 +39,7 @@ async def test_errors_out(): def test_does_not_import_unrelated_packages(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pkg_dir = pytester.mkpydir("mypkg") pkg_dir.joinpath("__init__.py").write_text( dedent( From 45649bd5c7f6327f94d07d7549ef7cd32a23ab3e Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Sat, 24 Aug 2024 22:05:25 +0200 Subject: [PATCH 18/18] refactor: Addressed warnigs about missing default fixture loop scope in tests/test_is_async_test.py, tests/test_simple.py, and tests/test_skips.py. --- tests/test_is_async_test.py | 4 ++++ tests/test_simple.py | 7 +++++-- tests/test_skips.py | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/test_is_async_test.py b/tests/test_is_async_test.py index e0df54de..d69a54f6 100644 --- a/tests/test_is_async_test.py +++ b/tests/test_is_async_test.py @@ -4,6 +4,7 @@ def test_returns_false_for_sync_item(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -28,6 +29,7 @@ def pytest_collection_modifyitems(items): def test_returns_true_for_marked_coroutine_item_in_strict_mode(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -53,6 +55,7 @@ def pytest_collection_modifyitems(items): def test_returns_false_for_unmarked_coroutine_item_in_strict_mode(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -77,6 +80,7 @@ def pytest_collection_modifyitems(items): def test_returns_true_for_unmarked_coroutine_item_in_auto_mode(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ diff --git a/tests/test_simple.py b/tests/test_simple.py index f5f52a8d..c40a6809 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -26,6 +26,7 @@ async def test_asyncio_marker(): def test_asyncio_marker_compatibility_with_xfail(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -45,6 +46,7 @@ async def test_asyncio_marker_fail(): def test_asyncio_auto_mode_compatibility_with_xfail(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -101,8 +103,9 @@ async def test_event_loop_before_fixture(self, loop): assert await loop.run_in_executor(None, self.foo) == 1 -def test_invalid_asyncio_mode(testdir): - result = testdir.runpytest("-o", "asyncio_mode=True") +def test_invalid_asyncio_mode(pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") + result = pytester.runpytest("-o", "asyncio_mode=True") result.stderr.no_fnmatch_line("INTERNALERROR> *") result.stderr.fnmatch_lines( "ERROR: 'True' is not a valid asyncio_mode. Valid modes: auto, strict." diff --git a/tests/test_skips.py b/tests/test_skips.py index 5d7aa303..96582ac0 100644 --- a/tests/test_skips.py +++ b/tests/test_skips.py @@ -4,6 +4,7 @@ def test_asyncio_strict_mode_skip(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -22,6 +23,7 @@ async def test_no_warning_on_skip(): def test_asyncio_auto_mode_skip(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -39,6 +41,7 @@ async def test_no_warning_on_skip(): def test_asyncio_strict_mode_module_level_skip(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -57,6 +60,7 @@ async def test_is_skipped(): def test_asyncio_auto_mode_module_level_skip(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -74,6 +78,7 @@ async def test_is_skipped(): def test_asyncio_auto_mode_wrong_skip_usage(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -91,6 +96,7 @@ async def test_is_skipped(): def test_unittest_skiptest_compatibility(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( dedent( """\ @@ -108,6 +114,7 @@ async def test_is_skipped(): def test_skip_in_module_does_not_skip_package(pytester: Pytester): + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") pytester.makepyfile( __init__="", test_skip=dedent(