Skip to content

Commit 0223ab1

Browse files
Support specifying postgresql drivers (#156)
* Support specifying postgresql drivers * Add "postgresql-pg8000" extra dep * Update setup.py Co-authored-by: Till Hoffmann <[email protected]> * Update postgres.py * Update postgres.py * fix whitespace Co-authored-by: Till Hoffmann <[email protected]>
1 parent 4cfe4c3 commit 0223ab1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

testcontainers/postgres.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ class PostgresContainer(DbContainer):
3232
POSTGRES_PASSWORD = os.environ.get("POSTGRES_PASSWORD", "test")
3333
POSTGRES_DB = os.environ.get("POSTGRES_DB", "test")
3434

35-
def __init__(self, image="postgres:latest", port=5432, user=None, password=None, dbname=None):
35+
def __init__(self,
36+
image="postgres:latest",
37+
port=5432, user=None,
38+
password=None,
39+
dbname=None,
40+
driver="psycopg2"):
3641
super(PostgresContainer, self).__init__(image=image)
3742
self.POSTGRES_USER = user or self.POSTGRES_USER
3843
self.POSTGRES_PASSWORD = password or self.POSTGRES_PASSWORD
3944
self.POSTGRES_DB = dbname or self.POSTGRES_DB
4045
self.port_to_expose = port
46+
self.driver = driver
4147

4248
self.with_exposed_ports(self.port_to_expose)
4349

@@ -47,7 +53,7 @@ def _configure(self):
4753
self.with_env("POSTGRES_DB", self.POSTGRES_DB)
4854

4955
def get_connection_url(self, host=None):
50-
return super()._create_connection_url(dialect="postgresql+psycopg2",
56+
return super()._create_connection_url(dialect="postgresql+{}".format(self.driver),
5157
username=self.POSTGRES_USER,
5258
password=self.POSTGRES_PASSWORD,
5359
db_name=self.POSTGRES_DB,

0 commit comments

Comments
 (0)