]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: use Windows asyncio policy in "non-asyncio" pool tests
authorDenis Laxalde <denis.laxalde@dalibo.com>
Sun, 5 Feb 2023 17:40:16 +0000 (18:40 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 6 Feb 2023 21:17:31 +0000 (21:17 +0000)
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.

tests/pool/test_pool_async_noasyncio.py

index f6e34e472d9a15b957309ae59e9cef6d6ae25665..982b9288e8a74dcb79ee91b09d75ac3e2acf8bb7 100644 (file)
@@ -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