From: Daniele Varrazzo Date: Sat, 20 Apr 2024 22:03:56 +0000 (+0200) Subject: test: fix running pool tests using Psycopg 3.1 X-Git-Tag: 3.2.0~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5adfbc9dfb8ae2d9f7378487615abf52538368da;p=thirdparty%2Fpsycopg.git test: fix running pool tests using Psycopg 3.1 Avoid using Capabilities at import time in the test suite. --- diff --git a/tests/fix_db.py b/tests/fix_db.py index 5f2a901eb..0c3fe0c8e 100644 --- a/tests/fix_db.py +++ b/tests/fix_db.py @@ -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 diff --git a/tests/test_capabilities.py b/tests/test_capabilities.py index 56331e413..2d27e62ec 100644 --- a/tests/test_capabilities.py +++ b/tests/test_capabilities.py @@ -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),