Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 65aa17f

Browse files
authored
Use pg.get_container_host_ip and pg.get_connection_url (#65)
1 parent 06c9fea commit 65aa17f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
⌛️ [running Python SDK tests](${{ env.RUN_URL }})...
6060
- run: poetry install
6161
- run: poetry run pytest -s
62+
env:
63+
TC_HOST: 172.17.0.1
6264
- name: Comment on failure
6365
if: ${{ github.event.inputs.prNumber && failure() }}
6466
uses: marocchino/sticky-pull-request-comment@v2

tests/conftest.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,28 @@ class SeamBackend:
2828
@pytest.fixture(scope="function")
2929
def seam_backend():
3030
with PostgresContainer("postgres:13", dbname="postgres") as pg:
31-
db_host = (
32-
"host.docker.internal"
33-
if sys.platform == "darwin"
34-
else "172.17.0.1"
35-
)
36-
db_url = f"postgresql://test:test@{db_host}:{pg.get_exposed_port(pg.port_to_expose)}/postgres"
31+
db_host = pg.get_container_host_ip()
32+
db_url = pg.get_connection_url()
33+
34+
# UPSTREAM: https://github.com/testcontainers/testcontainers-python/issues/159
35+
docker_info = pg.get_docker_client().client.info()
36+
if docker_info["OperatingSystem"] == "Docker Desktop":
37+
container_host = "host.docker.internal"
38+
db_url = db_url.replace(db_host, container_host)
39+
db_host = container_host
40+
3741
with DockerContainer(
3842
os.environ.get(
3943
"SEAM_CONNECT_IMAGE", "ghcr.io/seamapi/seam-connect"
4044
)
41-
).with_env("DATABASE_URL", db_url,).with_env(
45+
).with_env(
46+
"DATABASE_URL", db_url
47+
).with_env(
4248
"POSTGRES_DATABASE", "postgres"
4349
).with_env(
4450
"NODE_ENV", "test"
4551
).with_env(
46-
"POSTGRES_HOST", db_host
52+
"POSTGRES_HOST", db_host,
4753
).with_env(
4854
"SERVER_BASE_URL", "http://localhost:3020"
4955
).with_env(

0 commit comments

Comments
 (0)