]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: fix running pool tests using Psycopg 3.1
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 20 Apr 2024 22:03:56 +0000 (00:03 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 20 Apr 2024 22:12:25 +0000 (00:12 +0200)
Avoid using Capabilities at import time in the test suite.

tests/fix_db.py
tests/test_capabilities.py

index 5f2a901ebf060df95ab87a9c34eea76dde157226..0c3fe0c8e2971fcdfdd2b411f9a39c1256fa0e8a 100644 (file)
@@ -69,11 +69,11 @@ def pytest_collection_modifyitems(items):
 
 
 def pytest_runtest_setup(item):
-    try:
-        psycopg.capabilities.has_pipeline(check=True)
-    except psycopg.NotSupportedError as ex:
+    # Note: not using Capabilities.has_pipeline() to allow running the tests
+    # with Psycopg 3.1.
+    if not psycopg.Pipeline.is_supported():
         for m in item.iter_markers(name="pipeline"):
-            pytest.skip(str(ex))
+            pytest.skip("pipeline mode not supported")
 
 
 def pytest_configure(config):
@@ -215,10 +215,8 @@ def conn(conn_cls, dsn, request, tracefile):
 @pytest.fixture(params=[True, False], ids=["pipeline=on", "pipeline=off"])
 def pipeline(request, conn):
     if request.param:
-        try:
-            psycopg.capabilities.has_pipeline(check=True)
-        except psycopg.NotSupportedError as ex:
-            pytest.skip(str(ex))
+        if not psycopg.Pipeline.is_supported():
+            pytest.skip("pipeline mode not supported")
         with conn.pipeline() as p:
             yield p
         return
@@ -240,10 +238,8 @@ async def aconn(dsn, aconn_cls, request, tracefile):
 @pytest.fixture(params=[True, False], ids=["pipeline=on", "pipeline=off"])
 async def apipeline(request, aconn):
     if request.param:
-        try:
-            psycopg.capabilities.has_pipeline(check=True)
-        except psycopg.NotSupportedError as ex:
-            pytest.skip(str(ex))
+        if not psycopg.Pipeline.is_supported():
+            pytest.skip("pipeline mode not supported")
         async with aconn.pipeline() as p:
             yield p
         return
index 56331e4138c9c91859c15f1a7919f405691f1188..2d27e62ec92fc97227590962036557f1a5e2d42f 100644 (file)
@@ -3,7 +3,12 @@ import re
 import pytest
 
 from psycopg import pq, _cmodule
-from psycopg import Capabilities, capabilities, NotSupportedError
+
+try:
+    from psycopg import Capabilities, capabilities, NotSupportedError
+except ImportError:
+    # Allow to import the module with Psycopg 3.1
+    pass
 
 caps = [
     ("has_encrypt_password", "pq.PGconn.encrypt_password()", 10),