From d4c4ae0cf0f1f9874b1accc2eab67d9e9a9dc6e9 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 11 Mar 2025 00:26:23 +0100 Subject: [PATCH] test: skip target_session_attrs with libpw < 14 Only one test fails with the currently "oldest" libpq, which is 10.2, however the docs in libpq 13 are not explicit in which modes are supported and, afaics, 'replica' shouldn't work either. https://www.postgresql.org/docs/13/libpq-connect.html --- tests/test_connection.py | 7 ++++--- tests/test_connection_async.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index 4e477f6f0..60d2083a1 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -905,18 +905,19 @@ def test_right_exception_on_session_timeout(conn): assert type(ex.value) is want_ex -# NOTE: these "tsa" tests assume that the database we use for tests is a primary. - - +@pytest.mark.libpq(">= 14") @pytest.mark.parametrize("mode", ["any", "read-write", "primary", "prefer-standby"]) def test_connect_tsa(conn_cls, dsn, mode): + # NOTE: assume that the test database is a "primary" params = conninfo_to_dict(dsn, target_session_attrs=mode) with conn_cls.connect(**params) as conn: assert conn.pgconn.status == pq.ConnStatus.OK +@pytest.mark.libpq(">= 14") @pytest.mark.parametrize("mode", ["read-only", "standby", "nosuchmode"]) def test_connect_tsa_bad(conn_cls, dsn, mode): + # NOTE: assume that the test database is a "primary" params = conninfo_to_dict(dsn, target_session_attrs=mode) with pytest.raises(psycopg.OperationalError, match=mode): conn_cls.connect(**params) diff --git a/tests/test_connection_async.py b/tests/test_connection_async.py index 7662ea9e5..c8da671da 100644 --- a/tests/test_connection_async.py +++ b/tests/test_connection_async.py @@ -911,18 +911,19 @@ async def test_right_exception_on_session_timeout(aconn): assert type(ex.value) is want_ex -# NOTE: these "tsa" tests assume that the database we use for tests is a primary. - - +@pytest.mark.libpq(">= 14") @pytest.mark.parametrize("mode", ["any", "read-write", "primary", "prefer-standby"]) async def test_connect_tsa(aconn_cls, dsn, mode): + # NOTE: assume that the test database is a "primary" params = conninfo_to_dict(dsn, target_session_attrs=mode) async with await aconn_cls.connect(**params) as aconn: assert aconn.pgconn.status == pq.ConnStatus.OK +@pytest.mark.libpq(">= 14") @pytest.mark.parametrize("mode", ["read-only", "standby", "nosuchmode"]) async def test_connect_tsa_bad(aconn_cls, dsn, mode): + # NOTE: assume that the test database is a "primary" params = conninfo_to_dict(dsn, target_session_attrs=mode) with pytest.raises(psycopg.OperationalError, match=mode): await aconn_cls.connect(**params) -- 2.47.2