Skip to content

Commit 55e5000

Browse files
committed
fix work on windows only with docker testcontainers/testcontainers-python#108
1 parent 5ed3970 commit 55e5000

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎tests/integration/conftest.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from app.dao.holder import HolderDao
1111
from app.models.config import Config
12+
from tests.mocks.config import DBConfig
1213

1314
logger = logging.getLogger(__name__)
1415

@@ -34,10 +35,16 @@ def pool(postgres_url: str) -> sessionmaker:
3435

3536
@pytest.fixture(scope="session")
3637
def postgres_url(app_config: Config) -> str:
37-
if os.name == "nt": # windows testcontainers now not working
38-
yield app_config.db.uri
39-
else:
40-
with PostgresContainer("postgres:11") as postgres:
41-
postgres_url_ = postgres.get_connection_url().replace("psycopg2", "asyncpg")
42-
logger.info("postgres url %s", postgres_url_)
43-
yield postgres_url_
38+
39+
postgres = PostgresContainer("postgres:11")
40+
if os.name == "nt": # TODO workaround from testcontainers/testcontainers-python#108
41+
postgres.get_container_host_ip = lambda: 'localhost'
42+
try:
43+
postgres.start()
44+
postgres_url_ = postgres.get_connection_url().replace("psycopg2", "asyncpg")
45+
logger.info("postgres url %s", postgres_url_)
46+
app_config.db = DBConfig(postgres_url_)
47+
yield postgres_url_
48+
finally:
49+
postgres.stop()
50+

‎tests/mocks/__init__.py‎

Whitespace-only changes.

‎tests/mocks/config.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass
5+
class DBConfig:
6+
uri: str

0 commit comments

Comments
 (0)