Skip to content

Commit 1a143b0

Browse files
author
SergeyPirogov
committed
add host to fix db connection on windows
1 parent fa36a25 commit 1a143b0

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

testcontainers/core/generic.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ def _connect(self):
2929
def get_connection_url(self):
3030
raise NotImplementedError
3131

32-
def _create_connection_url(self, dialect, username, password, port, db_name=None):
32+
def _create_connection_url(self, dialect, username, password, host=None, port=None, db_name=None):
3333
if self._container is None:
3434
raise RuntimeError("container has not been started")
35-
host = self.get_container_host_ip()
35+
if not host:
36+
host = self.get_container_host_ip()
3637
port = self.get_exposed_port(port)
3738
url = "{dialect}://{username}:{password}@{host}:{port}".format(
3839
dialect=dialect, username=username, password=password, host=host, port=port

testcontainers/postgres.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ def _configure(self):
4646
self.with_env("POSTGRES_PASSWORD", self.POSTGRES_PASSWORD)
4747
self.with_env("POSTGRES_DB", self.POSTGRES_DB)
4848

49-
def get_connection_url(self):
49+
def get_connection_url(self, host="localhost"):
5050
return super()._create_connection_url(dialect="postgresql+psycopg2",
5151
username=self.POSTGRES_USER,
5252
password=self.POSTGRES_PASSWORD,
5353
db_name=self.POSTGRES_DB,
54+
host=host,
5455
port=self.port_to_expose)

0 commit comments

Comments
 (0)