]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
chore: use AnyIO 4.0+ in tests dependencies
authorDenis Laxalde <denis.laxalde@dalibo.com>
Wed, 18 Oct 2023 08:35:50 +0000 (10:35 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 20 Oct 2023 15:31:29 +0000 (16:31 +0100)
We set the 'loop_factory' asyncio option for parametrizing the
anyio_backend() fixture as anyio 4.0 has replaced the 'policy' option by
'loop_factory'.

In tests/pool/test_pool_async_noasyncio.py, we previously used
the anyio_backend_options fixture to retrieve the loop policy; now we
build it directly. This could be improved by using the loop_factory, but
only from Python 3.11 with an asyncio.Runner().

psycopg/setup.cfg
tests/conftest.py
tests/constraints.txt
tests/pool/test_pool_async_noasyncio.py

index b5ca4017aa094b91a93ad0ed9bf62d8aa3bf1ed4..900418f57308698b1f1e696c244f81f12bafc85a 100644 (file)
@@ -64,8 +64,7 @@ binary =
 pool =
     psycopg-pool
 test =
-    # TODO: move to anyio >= 4.0 once support for Python 3.7 is dropped
-    anyio >= 3.6.2, < 4.0
+    anyio >= 4.0
     mypy >= 1.4.1
     pproxy >= 2.7
     pytest >= 6.2.5
index ab3295448b1e18e5d7bfb8882088612f036aaaf4..05d79f9990db44352e75afb8ca0053e922532cef 100644 (file)
@@ -70,7 +70,9 @@ def pytest_sessionstart(session):
 
 asyncio_options: Dict[str, Any] = {}
 if sys.platform == "win32":
-    asyncio_options["policy"] = asyncio.WindowsSelectorEventLoopPolicy()
+    asyncio_options[
+        "loop_factory"
+    ] = asyncio.WindowsSelectorEventLoopPolicy().new_event_loop
 
 
 @pytest.fixture(
index 13021fa101d71f612f7cf57dde93182a8b9857f7..459f006e1bba31b94a836f2e9201d57d45b90530 100644 (file)
@@ -9,7 +9,7 @@ typing-extensions == 4.2.0
 importlib-metadata == 1.4
 
 # From the 'test' extra
-anyio == 3.6.2
+anyio == 4.0
 mypy == 1.4.1
 pproxy == 2.7.0
 pytest == 6.2.5
index 304aa4ceb54c883da69a9849240d8194f395544c..3b96d9a34614c7ed1bc05021d5394111fb9dd8a6 100644 (file)
@@ -2,6 +2,7 @@
 # because they rely on the pool initialization outside the asyncio loop.
 
 import asyncio
+import sys
 
 import pytest
 
@@ -62,18 +63,14 @@ def test_cant_create_open_outside_loop(dsn):
 
 
 @pytest.fixture
-def asyncio_run(anyio_backend_options, recwarn):
+def asyncio_run(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)
+    if sys.platform == "win32":
+        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
     recwarn.clear()
     try:
         yield asyncio.run