From b8395f1ae5106760eae92629b5e2b03303bb291a Mon Sep 17 00:00:00 2001 From: Iris Date: Tue, 26 May 2026 19:03:27 -0700 Subject: [PATCH] replace event_loop_policy --- test/asynchronous/conftest.py | 16 +++++----------- test/conftest.py | 15 +++++---------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/test/asynchronous/conftest.py b/test/asynchronous/conftest.py index a27a9f213d..afbd532a67 100644 --- a/test/asynchronous/conftest.py +++ b/test/asynchronous/conftest.py @@ -5,21 +5,15 @@ from test import pytest_conf from test.asynchronous import async_setup, async_teardown -import pytest import pytest_asyncio _IS_SYNC = False - -@pytest.fixture(scope="session") -def event_loop_policy(): - # The default asyncio loop implementation on Windows - # has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240) - # We explicitly use a different loop implementation here to prevent that issue - if sys.platform == "win32": - return asyncio.WindowsSelectorEventLoopPolicy() # type: ignore[attr-defined] - - return asyncio.get_event_loop_policy() +# The default asyncio loop implementation on Windows has issues with sharing +# sockets across loops (https://github.com/python/cpython/issues/122240). +# We explicitly use a different loop implementation here to prevent that issue +if sys.platform == "win32": + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined] @pytest_asyncio.fixture(scope="package", autouse=True) diff --git a/test/conftest.py b/test/conftest.py index 91fad28d0a..eb12d9f928 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -8,16 +8,11 @@ _IS_SYNC = True - -@pytest.fixture(scope="session") -def event_loop_policy(): - # The default asyncio loop implementation on Windows - # has issues with sharing sockets across loops (https://github.com/python/cpython/issues/122240) - # We explicitly use a different loop implementation here to prevent that issue - if sys.platform == "win32": - return asyncio.WindowsSelectorEventLoopPolicy() # type: ignore[attr-defined] - - return asyncio.get_event_loop_policy() +# The default asyncio loop implementation on Windows has issues with sharing +# sockets across loops (https://github.com/python/cpython/issues/122240). +# We explicitly use a different loop implementation here to prevent that issue +if sys.platform == "win32": + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore[attr-defined] @pytest.fixture(scope="package", autouse=True)