From 2c9b7cda5c3447e2cd848f9be3fd364c485a3d85 Mon Sep 17 00:00:00 2001 From: Sai Sridhar Date: Sat, 30 May 2026 17:07:08 +0530 Subject: [PATCH 1/3] fix: default asyncio_default_fixture_loop_scope to "function" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The configuration option was previously left unset (None), causing pytest-asyncio to emit a PytestDeprecationWarning on every run and fall back to fixture-caching scope — the old deprecated behaviour. Set the default to "function" as documented in the issue roadmap. Remove the now-unreachable _DEFAULT_FIXTURE_LOOP_SCOPE_UNSET constant and its associated warning emission in pytest_configure. Tests that explicitly set `asyncio_default_fixture_loop_scope = function` in pytester configs are still correct; removing those redundant settings is left as a follow-up. Closes #924 --- pytest_asyncio/plugin.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 2fe8db12..fb403c71 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -137,7 +137,7 @@ def pytest_addoption(parser: Parser, pluginmanager: PytestPluginManager) -> None "asyncio_default_fixture_loop_scope", type="string", help="default scope of the asyncio event loop used to execute async fixtures", - default=None, + default="function", ) parser.addini( "asyncio_default_test_loop_scope", @@ -271,14 +271,6 @@ def _collect_hook_loop_factories( return factories -_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET = """\ -The configuration option "asyncio_default_fixture_loop_scope" is unset. -The event loop scope for asynchronous fixtures will default to the "fixture" caching \ -scope. Future versions of pytest-asyncio will default the loop scope for asynchronous \ -fixtures to "function" scope. Set the default fixture loop scope explicitly in order \ -to avoid unexpected behavior in the future. Valid fixture loop scopes are: \ -"function", "class", "module", "package", "session" -""" def _validate_scope(scope: str | None, option_name: str) -> None: @@ -295,9 +287,6 @@ def _validate_scope(scope: str | None, option_name: str) -> None: def pytest_configure(config: Config) -> None: default_fixture_loop_scope = config.getini("asyncio_default_fixture_loop_scope") _validate_scope(default_fixture_loop_scope, "asyncio_default_fixture_loop_scope") - if not default_fixture_loop_scope: - warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET)) - default_test_loop_scope = config.getini("asyncio_default_test_loop_scope") _validate_scope(default_test_loop_scope, "asyncio_default_test_loop_scope") config.addinivalue_line( From d54e5cae01f1cf900b241d35fec3257b20e67906 Mon Sep 17 00:00:00 2001 From: Sai Sridhar Date: Sat, 30 May 2026 17:17:08 +0530 Subject: [PATCH 2/3] style: apply shed formatting after deprecation removal --- pytest_asyncio/plugin.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index fb403c71..53885d1e 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -271,8 +271,6 @@ def _collect_hook_loop_factories( return factories - - def _validate_scope(scope: str | None, option_name: str) -> None: if scope is None: return From 9733864fb72c017e7c4e1786a855c0e516f6f63a Mon Sep 17 00:00:00 2001 From: Sai Sridhar Date: Sat, 30 May 2026 17:40:14 +0530 Subject: [PATCH 3/3] changelog: add news fragment for #924 --- changelog.d/924.changed.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog.d/924.changed.rst diff --git a/changelog.d/924.changed.rst b/changelog.d/924.changed.rst new file mode 100644 index 00000000..b067f113 --- /dev/null +++ b/changelog.d/924.changed.rst @@ -0,0 +1,3 @@ +``asyncio_default_fixture_loop_scope`` now defaults to ``"function"`` instead of being unset. +Previously, leaving the option unset caused a ``PytestDeprecationWarning`` on every test run. +The old deprecation warning and its associated constant have been removed.