From: Denis Laxalde Date: Sun, 5 Feb 2023 17:40:16 +0000 (+0100) Subject: test: use Windows asyncio policy in "non-asyncio" pool tests X-Git-Tag: pool-3.1.7~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4696d1552a0a34031fb2d2160134dba9d941362;p=thirdparty%2Fpsycopg.git test: use Windows asyncio policy in "non-asyncio" pool tests In commit b6cc8343159fc0a27365e09a3beef06433f3f1b5, we drop the global asyncio.set_event_loop_policy() for Windows in conftest.py, replacing it with asyncio_options to be used by the anyio test runner. However, test cases in test_pool_async_noasyncio.py are not "async def" so they would not use that anyio runner (nor did they use pytest-asyncio's runner before); but they need the event loop policy for Windows still. Accordingly, we configure the loop from "anyio_backend_options" in asyncio_run() fixture. --- diff --git a/tests/pool/test_pool_async_noasyncio.py b/tests/pool/test_pool_async_noasyncio.py index f6e34e472..982b9288e 100644 --- a/tests/pool/test_pool_async_noasyncio.py +++ b/tests/pool/test_pool_async_noasyncio.py @@ -61,12 +61,18 @@ def test_cant_create_open_outside_loop(dsn): @pytest.fixture -def asyncio_run(recwarn): +def asyncio_run(anyio_backend_options, recwarn): """Fixture reuturning asyncio.run, but managing resources at exit. In certain runs, fd objects are leaked and the error will only be caught downstream, by some innocent test calling gc_collect(). """ + try: + policy = anyio_backend_options["policy"] + except KeyError: + pass + else: + asyncio.set_event_loop_policy(policy) recwarn.clear() try: yield asyncio.run