]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Fix test for ConnectionInfo.hostaddr and libpq < 12
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 5 May 2021 16:32:06 +0000 (18:32 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 9 May 2021 23:05:32 +0000 (01:05 +0200)
docs/api/connections.rst
tests/test_conninfo.py

index 113dec25b76c14dd00fc802f750012a33f318dba..8137363913b9ac6ed64f4f8fb2b3e64aaa13df9f 100644 (file)
@@ -283,6 +283,9 @@ Connection support objects
 
     .. autoattribute:: hostaddr
 
+        Only available if the libpq used is at least from PostgreSQL 12.
+        Raise `~psycopg3.NotSupportedError` otherwise.
+
     .. autoattribute:: port
     .. autoattribute:: dbname
     .. autoattribute:: user
index ff5e9544e302350a028cf805dbb88f94bbbf41f0..be1e706ed4b2e19b01e99a268d90b6eecbb8625a 100644 (file)
@@ -98,6 +98,9 @@ class TestConnectionInfo:
         else:
             info_attr = pgconn_attr = attr
 
+        if info_attr == "hostaddr" and psycopg3.pq.version() < 120000:
+            pytest.skip("hostaddr not supported on libpq < 12")
+
         info_val = getattr(conn.info, info_attr)
         pgconn_val = getattr(conn.pgconn, pgconn_attr).decode("utf-8")
         assert info_val == pgconn_val
@@ -106,6 +109,11 @@ class TestConnectionInfo:
         with pytest.raises(psycopg3.OperationalError):
             getattr(conn.info, info_attr)
 
+    @pytest.mark.libpq("< 12")
+    def test_hostaddr_not_supported(self, conn):
+        with pytest.raises(psycopg3.NotSupportedError):
+            conn.info.hostaddr
+
     def test_port(self, conn):
         assert conn.info.port == int(conn.pgconn.port.decode("utf-8"))
         conn.close()