diff --git a/changelog.d/1517.removed.rst b/changelog.d/1517.removed.rst new file mode 100644 index 00000000..7ca99af9 --- /dev/null +++ b/changelog.d/1517.removed.rst @@ -0,0 +1 @@ +Deprecated *event_loop_policy* fixture diff --git a/docs/how-to-guides/index.rst b/docs/how-to-guides/index.rst index b67a4125..e927358c 100644 --- a/docs/how-to-guides/index.rst +++ b/docs/how-to-guides/index.rst @@ -16,7 +16,6 @@ How-To Guides run_class_tests_in_same_loop run_module_tests_in_same_loop run_package_tests_in_same_loop - multiple_loops parametrize_with_asyncio uvloop test_item_is_async diff --git a/docs/how-to-guides/multiple_loops.rst b/docs/how-to-guides/multiple_loops.rst deleted file mode 100644 index 7ebf0616..00000000 --- a/docs/how-to-guides/multiple_loops.rst +++ /dev/null @@ -1,14 +0,0 @@ -====================================== -How to test with different event loops -====================================== - -.. warning:: - - Overriding the *event_loop_policy* fixture is deprecated and will be removed in a future version of pytest-asyncio. Use the ``pytest_asyncio_loop_factories`` hook instead. See :doc:`custom_loop_factory` for details. - -Parametrizing the *event_loop_policy* fixture parametrizes all async tests. The following example causes all async tests to run multiple times, once for each event loop in the fixture parameters: - -.. include:: multiple_loops_example.py - :code: python - -You may choose to limit the scope of the fixture to *package,* *module,* or *class,* if you only want a subset of your tests to run with different event loops. diff --git a/docs/how-to-guides/multiple_loops_example.py b/docs/how-to-guides/multiple_loops_example.py deleted file mode 100644 index 2083e8b6..00000000 --- a/docs/how-to-guides/multiple_loops_example.py +++ /dev/null @@ -1,29 +0,0 @@ -import asyncio -import warnings - -with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - from asyncio import DefaultEventLoopPolicy - -import pytest - - -class CustomEventLoopPolicy(DefaultEventLoopPolicy): - pass - - -@pytest.fixture( - scope="session", - params=( - CustomEventLoopPolicy(), - CustomEventLoopPolicy(), - ), -) -def event_loop_policy(request): - return request.param - - -@pytest.mark.asyncio -@pytest.mark.filterwarnings("ignore::DeprecationWarning") -async def test_uses_custom_event_loop_policy(): - assert isinstance(asyncio.get_event_loop_policy(), CustomEventLoopPolicy) diff --git a/docs/how-to-guides/uvloop.rst b/docs/how-to-guides/uvloop.rst index 03143be5..8239d94d 100644 --- a/docs/how-to-guides/uvloop.rst +++ b/docs/how-to-guides/uvloop.rst @@ -18,24 +18,3 @@ Define a ``pytest_asyncio_loop_factories`` hook in your *conftest.py* that maps :doc:`custom_loop_factory` More details on the ``pytest_asyncio_loop_factories`` hook, including per-test factory selection and multiple factory parametrization. - -Using the event_loop_policy fixture ------------------------------------ - -.. note:: - - ``asyncio.AbstractEventLoopPolicy`` is deprecated as of Python 3.14 (removal planned for 3.16), and ``uvloop.EventLoopPolicy`` will be removed alongside it. Overriding the *event_loop_policy* fixture is also deprecated in pytest-asyncio. Prefer the hook approach above. - -For older versions of Python and uvloop, you can override the *event_loop_policy* fixture in your *conftest.py:* - -.. code-block:: python - - import pytest - import uvloop - - - @pytest.fixture(scope="session") - def event_loop_policy(): - return uvloop.EventLoopPolicy() - -You may choose to limit the scope of the fixture to *package,* *module,* or *class,* if you only want a subset of your tests to run with uvloop. diff --git a/docs/reference/fixtures/event_loop_policy_example.py b/docs/reference/fixtures/event_loop_policy_example.py deleted file mode 100644 index e8642527..00000000 --- a/docs/reference/fixtures/event_loop_policy_example.py +++ /dev/null @@ -1,23 +0,0 @@ -import asyncio -import warnings - -with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - from asyncio import DefaultEventLoopPolicy - -import pytest - - -class CustomEventLoopPolicy(DefaultEventLoopPolicy): - pass - - -@pytest.fixture(scope="module") -def event_loop_policy(request): - return CustomEventLoopPolicy() - - -@pytest.mark.asyncio(loop_scope="module") -@pytest.mark.filterwarnings("ignore::DeprecationWarning") -async def test_uses_custom_event_loop_policy(): - assert isinstance(asyncio.get_event_loop_policy(), CustomEventLoopPolicy) diff --git a/docs/reference/fixtures/event_loop_policy_parametrized_example.py b/docs/reference/fixtures/event_loop_policy_parametrized_example.py deleted file mode 100644 index 19552d81..00000000 --- a/docs/reference/fixtures/event_loop_policy_parametrized_example.py +++ /dev/null @@ -1,28 +0,0 @@ -import asyncio -import warnings - -with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - from asyncio import DefaultEventLoopPolicy - -import pytest - - -class CustomEventLoopPolicy(DefaultEventLoopPolicy): - pass - - -@pytest.fixture( - params=( - DefaultEventLoopPolicy(), - CustomEventLoopPolicy(), - ), -) -def event_loop_policy(request): - return request.param - - -@pytest.mark.asyncio -@pytest.mark.filterwarnings("ignore::DeprecationWarning") -async def test_uses_custom_event_loop_policy(): - assert isinstance(asyncio.get_event_loop_policy(), DefaultEventLoopPolicy) diff --git a/docs/reference/fixtures/index.rst b/docs/reference/fixtures/index.rst index 2791a484..ade01d18 100644 --- a/docs/reference/fixtures/index.rst +++ b/docs/reference/fixtures/index.rst @@ -2,29 +2,6 @@ Fixtures ======== -event_loop_policy -================= - -.. warning:: - - Overriding the *event_loop_policy* fixture is deprecated and will be removed in a future version of pytest-asyncio. Use the ``pytest_asyncio_loop_factories`` hook instead. See :doc:`../hooks` for details. - -Returns the event loop policy used to create asyncio event loops. -The default return value is *asyncio.get_event_loop_policy().* - -This fixture can be overridden when a different event loop policy should be used. - -.. include:: event_loop_policy_example.py - :code: python - -Multiple policies can be provided via fixture parameters. -The fixture is automatically applied to all pytest-asyncio tests. -Therefore, all tests managed by pytest-asyncio are run once for each fixture parameter. -The following example runs the test with different event loop policies. - -.. include:: event_loop_policy_parametrized_example.py - :code: python - unused_tcp_port =============== Finds and yields a single unused TCP port on the localhost interface. Useful for diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 38b75e41..2255b4d0 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -805,11 +805,8 @@ def _temporary_event_loop(loop: AbstractEventLoop) -> Iterator[None]: @contextlib.contextmanager -def _temporary_event_loop_policy( - policy: AbstractEventLoopPolicy, -) -> Iterator[None]: +def _restore_event_loop_policy() -> Iterator[None]: old_loop_policy = _get_event_loop_policy() - _set_event_loop_policy(policy) try: yield finally: @@ -910,13 +907,6 @@ def inner(*args, **kwargs): @pytest.hookimpl(wrapper=True) def pytest_fixture_setup(fixturedef: FixtureDef, request) -> object | None: - if ( - fixturedef.argname == "event_loop_policy" - and fixturedef.func.__module__ != __name__ - ): - warnings.warn( - PytestDeprecationWarning(_EVENT_LOOP_POLICY_FIXTURE_DEPRECATION_WARNING), - ) asyncio_mode = _get_asyncio_mode(request.config) if not _is_asyncio_fixture_function(fixturedef.func): if asyncio_mode == Mode.STRICT: @@ -960,12 +950,6 @@ def pytest_fixture_setup(fixturedef: FixtureDef, request) -> object | None: mark.asyncio 'loop_factories' must be a non-empty sequence of strings. """ -_EVENT_LOOP_POLICY_FIXTURE_DEPRECATION_WARNING = """\ -Overriding the "event_loop_policy" fixture is deprecated \ -and will be removed in a future version of pytest-asyncio. \ -Use the "pytest_asyncio_loop_factories" hook to customize event loop creation.\ -""" - def _parse_asyncio_marker( asyncio_marker: Mark, @@ -1027,13 +1011,11 @@ def _create_scoped_runner_fixture(scope: _ScopeName) -> Callable: name=f"_{scope}_scoped_runner", ) def _scoped_runner( - event_loop_policy, _asyncio_loop_factory, request: FixtureRequest, ) -> Iterator[Runner]: - new_loop_policy = event_loop_policy debug_mode = _get_asyncio_debug(request.config) - with _temporary_event_loop_policy(new_loop_policy): + with _restore_event_loop_policy(): runner = Runner( debug=debug_mode, loop_factory=_asyncio_loop_factory, @@ -1074,12 +1056,6 @@ def _asyncio_loop_factory(request: FixtureRequest) -> LoopFactory | None: return getattr(request, "param", None) -@pytest.fixture(scope="session", autouse=True) -def event_loop_policy() -> AbstractEventLoopPolicy: - """Return an instance of the policy used to create asyncio event loops.""" - return _get_event_loop_policy() - - def is_async_test(item: Item) -> TypeIs[PytestAsyncioFunction]: """Returns whether a test item is a pytest-asyncio test""" return isinstance(item, PytestAsyncioFunction) diff --git a/tests/markers/test_class_scope.py b/tests/markers/test_class_scope.py index ce023fcc..45583c3a 100644 --- a/tests/markers/test_class_scope.py +++ b/tests/markers/test_class_scope.py @@ -3,7 +3,6 @@ from __future__ import annotations import asyncio -import sys from textwrap import dedent import pytest @@ -98,83 +97,6 @@ async def test_this_runs_in_same_loop(self): result.assert_outcomes(passed=2) -def test_asyncio_mark_respects_the_loop_policy( - pytester: pytest.Pytester, -): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makepyfile(dedent("""\ - import asyncio - import pytest - - class CustomEventLoopPolicy(asyncio.DefaultEventLoopPolicy): - pass - - class TestUsesCustomEventLoop: - @pytest.fixture(scope="class") - @classmethod - def event_loop_policy(cls): - return CustomEventLoopPolicy() - - @pytest.mark.asyncio - async def test_uses_custom_event_loop_policy(self): - assert isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - - @pytest.mark.asyncio - async def test_does_not_use_custom_event_loop_policy(): - assert not isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - """)) - 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=4) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=2) - - -def test_asyncio_mark_respects_parametrized_loop_policies( - pytester: pytest.Pytester, -): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makepyfile(dedent("""\ - import asyncio - - import pytest - - @pytest.fixture( - scope="class", - params=[ - asyncio.DefaultEventLoopPolicy(), - asyncio.DefaultEventLoopPolicy(), - ] - ) - def event_loop_policy(request): - return request.param - - @pytest.mark.asyncio(loop_scope="class") - class TestWithDifferentLoopPolicies: - async def test_parametrized_loop(self, request): - pass - """)) - 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=4) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=2) - - def test_asyncio_mark_provides_class_scoped_loop_to_fixtures( pytester: pytest.Pytester, ): diff --git a/tests/markers/test_function_scope.py b/tests/markers/test_function_scope.py index 180d5c71..e3a264c4 100644 --- a/tests/markers/test_function_scope.py +++ b/tests/markers/test_function_scope.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from textwrap import dedent from pytest import Pytester @@ -77,128 +76,6 @@ async def test_warns(): result.stdout.fnmatch_lines("*DeprecationWarning*") -def test_asyncio_mark_respects_the_loop_policy( - pytester: Pytester, -): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makepyfile( - dedent("""\ - import asyncio - import pytest - - pytestmark = pytest.mark.asyncio - - class CustomEventLoopPolicy(asyncio.DefaultEventLoopPolicy): - pass - - @pytest.fixture(scope="function") - def event_loop_policy(): - return CustomEventLoopPolicy() - - async def test_uses_custom_event_loop_policy(): - assert isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - """), - ) - 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=3) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=1) - - -def test_asyncio_mark_respects_parametrized_loop_policies( - pytester: Pytester, -): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makepyfile(dedent("""\ - import asyncio - - import pytest - - pytestmark = pytest.mark.asyncio - - class CustomEventLoopPolicy(asyncio.DefaultEventLoopPolicy): - pass - - @pytest.fixture( - scope="module", - params=[ - CustomEventLoopPolicy(), - CustomEventLoopPolicy(), - ], - ) - def event_loop_policy(request): - return request.param - - async def test_parametrized_loop(): - assert isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - """)) - 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=5) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=2) - - -def test_event_loop_policy_fixture_override_emits_deprecation_warning( - pytester: Pytester, -): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makepyfile( - dedent("""\ - import asyncio - import pytest - - pytestmark = pytest.mark.asyncio - - @pytest.fixture - def event_loop_policy(): - return asyncio.DefaultEventLoopPolicy() - - async def test_anything(): - pass - """), - ) - result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") - result.assert_outcomes(passed=1) - result.stdout.fnmatch_lines( - "*PytestDeprecationWarning*event_loop_policy*deprecated*" - ) - - -def test_default_event_loop_policy_fixture_does_not_warn( - pytester: Pytester, -): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makepyfile( - dedent("""\ - import pytest - - pytestmark = pytest.mark.asyncio - - async def test_anything(): - pass - """), - ) - result = pytester.runpytest("--asyncio-mode=strict", "-W", "default") - result.assert_outcomes(passed=1) - result.stdout.no_fnmatch_line("*PytestDeprecationWarning*event_loop_policy*") - - def test_asyncio_mark_provides_function_scoped_loop_to_fixtures( pytester: Pytester, ): diff --git a/tests/markers/test_module_scope.py b/tests/markers/test_module_scope.py index a2662812..a814a9d7 100644 --- a/tests/markers/test_module_scope.py +++ b/tests/markers/test_module_scope.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from textwrap import dedent from pytest import Pytester @@ -33,97 +32,6 @@ async def test_this_runs_in_same_loop(self): result.assert_outcomes(passed=3) -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("""\ - import asyncio - - class CustomEventLoopPolicy(asyncio.DefaultEventLoopPolicy): - pass - """), - test_uses_custom_policy=dedent("""\ - import asyncio - import pytest - - from .custom_policy import CustomEventLoopPolicy - - pytestmark = pytest.mark.asyncio(loop_scope="module") - - @pytest.fixture(scope="module") - def event_loop_policy(): - return CustomEventLoopPolicy() - - async def test_uses_custom_event_loop_policy(): - assert isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - """), - test_does_not_use_custom_policy=dedent("""\ - import asyncio - import pytest - - from .custom_policy import CustomEventLoopPolicy - - pytestmark = pytest.mark.asyncio(loop_scope="module") - - async def test_does_not_use_custom_event_loop_policy(): - assert not isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - """), - ) - 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=4) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=2) - - -def test_asyncio_mark_respects_parametrized_loop_policies( - pytester: Pytester, -): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makepyfile(dedent("""\ - import asyncio - - import pytest - - pytestmark = pytest.mark.asyncio(loop_scope="module") - - @pytest.fixture( - scope="module", - params=[ - asyncio.DefaultEventLoopPolicy(), - asyncio.DefaultEventLoopPolicy(), - ], - ) - def event_loop_policy(request): - return request.param - - async def test_parametrized_loop(): - pass - """)) - 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=4) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=2) - - def test_asyncio_mark_provides_module_scoped_loop_to_fixtures( pytester: Pytester, ): diff --git a/tests/markers/test_package_scope.py b/tests/markers/test_package_scope.py index ff6aba4a..88ee2678 100644 --- a/tests/markers/test_package_scope.py +++ b/tests/markers/test_package_scope.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from textwrap import dedent from pytest import Pytester @@ -60,105 +59,6 @@ async def test_subpackage_runs_in_different_loop(): result.assert_outcomes(passed=4) -def test_asyncio_mark_respects_the_loop_policy( - pytester: Pytester, -): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makepyfile( - __init__="", - conftest=dedent("""\ - import pytest - - from .custom_policy import CustomEventLoopPolicy - - @pytest.fixture(scope="package") - def event_loop_policy(): - return CustomEventLoopPolicy() - """), - custom_policy=dedent("""\ - import asyncio - - class CustomEventLoopPolicy(asyncio.DefaultEventLoopPolicy): - pass - """), - test_uses_custom_policy=dedent("""\ - import asyncio - import pytest - - from .custom_policy import CustomEventLoopPolicy - - pytestmark = pytest.mark.asyncio(loop_scope="package") - - async def test_uses_custom_event_loop_policy(): - assert isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - """), - test_also_uses_custom_policy=dedent("""\ - import asyncio - import pytest - - from .custom_policy import CustomEventLoopPolicy - - pytestmark = pytest.mark.asyncio(loop_scope="package") - - async def test_also_uses_custom_event_loop_policy(): - assert isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - """), - ) - 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=4) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=2) - - -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("""\ - import asyncio - - import pytest - - pytestmark = pytest.mark.asyncio(loop_scope="package") - - @pytest.fixture( - scope="package", - params=[ - asyncio.DefaultEventLoopPolicy(), - asyncio.DefaultEventLoopPolicy(), - ], - ) - def event_loop_policy(request): - return request.param - - async def test_parametrized_loop(): - pass - """), - ) - 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=4) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=2) - - def test_asyncio_mark_provides_package_scoped_loop_to_fixtures( pytester: Pytester, ): diff --git a/tests/markers/test_session_scope.py b/tests/markers/test_session_scope.py index 24566c5e..07ccdaa7 100644 --- a/tests/markers/test_session_scope.py +++ b/tests/markers/test_session_scope.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from textwrap import dedent from pytest import Pytester @@ -61,105 +60,6 @@ async def test_subpackage_runs_in_same_loop(): result.assert_outcomes(passed=4) -def test_asyncio_mark_respects_the_loop_policy( - pytester: Pytester, -): - pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") - pytester.makepyfile( - __init__="", - conftest=dedent("""\ - import pytest - - from .custom_policy import CustomEventLoopPolicy - - @pytest.fixture(scope="session") - def event_loop_policy(): - return CustomEventLoopPolicy() - """), - custom_policy=dedent("""\ - import asyncio - - class CustomEventLoopPolicy(asyncio.DefaultEventLoopPolicy): - pass - """), - test_uses_custom_policy=dedent("""\ - import asyncio - import pytest - - from .custom_policy import CustomEventLoopPolicy - - pytestmark = pytest.mark.asyncio(loop_scope="session") - - async def test_uses_custom_event_loop_policy(): - assert isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - """), - test_also_uses_custom_policy=dedent("""\ - import asyncio - import pytest - - from .custom_policy import CustomEventLoopPolicy - - pytestmark = pytest.mark.asyncio(loop_scope="session") - - async def test_also_uses_custom_event_loop_policy(): - assert isinstance( - asyncio.get_event_loop_policy(), - CustomEventLoopPolicy, - ) - """), - ) - 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=4) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=2) - - -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("""\ - import asyncio - - import pytest - - pytestmark = pytest.mark.asyncio(loop_scope="session") - - @pytest.fixture( - scope="session", - params=[ - asyncio.DefaultEventLoopPolicy(), - asyncio.DefaultEventLoopPolicy(), - ], - ) - def event_loop_policy(request): - return request.param - - async def test_parametrized_loop(): - pass - """), - ) - 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=4) - result.stdout.fnmatch_lines("*DefaultEventLoopPolicy*") - else: - result.assert_outcomes(passed=2) - - def test_asyncio_mark_provides_session_scoped_loop_to_fixtures( pytester: Pytester, ):