From: Daniele Varrazzo Date: Thu, 13 Jan 2022 16:17:37 +0000 (+0100) Subject: Configure the async loop at test session start X-Git-Tag: pool-3.1~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51419656360646439dd59467a38f2b4d080e0c96;p=thirdparty%2Fpsycopg.git Configure the async loop at test session start Doing it in a fixture is too late: event_loop might have already been called if the first test running is async, and it would fail on Windows. This started to be needed after pytest-asyncio 0.17.0 was released. See . --- diff --git a/tests/conftest.py b/tests/conftest.py index d22c86f86..77c08ce1b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -62,13 +62,9 @@ def retries(request): ) -@pytest.fixture -def event_loop(request): - """Return the event loop to test asyncio-marked tests.""" - # pytest-asyncio reset the the loop config after each test, so set - # set them each time - - loop = request.config.getoption("--loop") +def pytest_sessionstart(session): + # Configure the async loop. + loop = session.config.getoption("--loop") if loop == "uvloop": import uvloop @@ -76,10 +72,5 @@ def event_loop(request): else: assert loop == "default" - loop = None if sys.platform == "win32": asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) - if not loop: - loop = asyncio.get_event_loop_policy().new_event_loop() - yield loop - loop.close()