]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: display the version of the server tests are run against
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 27 Mar 2022 18:52:57 +0000 (20:52 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 27 Mar 2022 19:50:54 +0000 (21:50 +0200)
tests/fix_db.py

index 1702a4ad248eda3a2421fd2d49dbaccf0af17601..ab4a6dd3b9a0102bc1a01a546716809f41beaaec 100644 (file)
@@ -27,6 +27,22 @@ def pytest_addoption(parser):
     )
 
 
+def pytest_report_header(config):
+    dsn = config.getoption("--test-dsn")
+    if dsn is None:
+        return []
+
+    try:
+        with psycopg.connect(dsn, connect_timeout=10) as conn:
+            server_version = conn.execute("select version()").fetchall()[0][0]
+    except Exception as ex:
+        server_version = f"unknown ({ex})"
+
+    return [
+        f"Server version: {server_version}",
+    ]
+
+
 def pytest_configure(config):
     # register pg marker
     config.addinivalue_line(