summary refs log tree commit diff
path: root/tests/utils.py
diff options
context:
space:
mode:
authorreivilibre <oliverw@matrix.org>2022-04-05 12:44:48 +0100
committerGitHub <noreply@github.com>2022-04-05 12:44:48 +0100
commit708d88b1a22d422c294c4d06f2896a24f2a0251d (patch)
treeb000fd7958d2da40bb7de58d3575d5cf271d1d3e /tests/utils.py
parentMerge tag 'v1.56.0rc1' into develop (diff)
downloadsynapse-708d88b1a22d422c294c4d06f2896a24f2a0251d.tar.xz
Allow specifying the Postgres database's port when running unit tests with Postgres. (#12376)
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py
index f6b1d60371..d4ba3a9b99 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -35,6 +35,11 @@ LEAVE_DB = os.environ.get("SYNAPSE_LEAVE_DB", False)
 POSTGRES_USER = os.environ.get("SYNAPSE_POSTGRES_USER", None)
 POSTGRES_HOST = os.environ.get("SYNAPSE_POSTGRES_HOST", None)
 POSTGRES_PASSWORD = os.environ.get("SYNAPSE_POSTGRES_PASSWORD", None)
+POSTGRES_PORT = (
+    int(os.environ["SYNAPSE_POSTGRES_PORT"])
+    if "SYNAPSE_POSTGRES_PORT" in os.environ
+    else None
+)
 POSTGRES_BASE_DB = "_synapse_unit_tests_base_%s" % (os.getpid(),)
 
 # When debugging a specific test, it's occasionally useful to write the
@@ -55,6 +60,7 @@ def setupdb():
         db_conn = db_engine.module.connect(
             user=POSTGRES_USER,
             host=POSTGRES_HOST,
+            port=POSTGRES_PORT,
             password=POSTGRES_PASSWORD,
             dbname=POSTGRES_DBNAME_FOR_INITIAL_CREATE,
         )
@@ -73,6 +79,7 @@ def setupdb():
             database=POSTGRES_BASE_DB,
             user=POSTGRES_USER,
             host=POSTGRES_HOST,
+            port=POSTGRES_PORT,
             password=POSTGRES_PASSWORD,
         )
         db_conn = LoggingDatabaseConnection(db_conn, db_engine, "tests")
@@ -83,6 +90,7 @@ def setupdb():
             db_conn = db_engine.module.connect(
                 user=POSTGRES_USER,
                 host=POSTGRES_HOST,
+                port=POSTGRES_PORT,
                 password=POSTGRES_PASSWORD,
                 dbname=POSTGRES_DBNAME_FOR_INITIAL_CREATE,
             )