]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: fix proxy-based tests confused by the PGHOST env var
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 12 Jul 2022 23:29:19 +0000 (00:29 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 12 Jul 2022 23:38:29 +0000 (00:38 +0100)
tests/fix_proxy.py

index 7101aac3df3406ddfb3a800bdc1d14870f6213d8..e50f5ec05f28b460cc7c9c349f055db763a64ad3 100644 (file)
@@ -1,3 +1,4 @@
+import os
 import time
 import socket
 import logging
@@ -57,11 +58,9 @@ class Proxy:
         cdict = conninfo.conninfo_to_dict(server_dsn)
 
         # Get server params
+        host = cdict.get("host") or os.environ.get("PGHOST")
+        self.server_host = host if host and not host.startswith("/") else "localhost"
         self.server_port = cdict.get("port", "5432")
-        if "host" not in cdict or cdict["host"].startswith("/"):
-            self.server_host = "localhost"
-        else:
-            self.server_host = cdict["host"]
 
         # Get client params
         self.client_host = "localhost"