Skip to content

Commit fe54d58

Browse files
Using tenacity for wait
1 parent b30c8d8 commit fe54d58

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ dev = [
2020
"pytest-asyncio",
2121
"assertpy",
2222
"ruff",
23-
"retrying",
23+
"tenacity",
2424
]

tests_integration/conftest.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
import pytest
66
import structlog
7+
from assertpy import assert_that
78
from fastapi.testclient import TestClient
9+
from tenacity import Retrying, stop_after_delay, wait_fixed
810
from testcontainers.core.container import DockerContainer
9-
from testcontainers.core.waiting_utils import wait_for_logs
1011

1112
import app.config as config
12-
import app.main as main
1313
import app.db_schema_migrations.yoyo_migration as yoyo_migration
14+
import app.main as main
1415

1516

1617
@pytest.fixture(scope="session")
@@ -24,11 +25,14 @@ def postgres_docker_container() -> Generator[DockerContainer, None, None]:
2425
env=env_vars,
2526
ports=[5432],
2627
) as container:
27-
wait_for_logs(container, "server started")
28-
stdout, stderr = container.get_logs()
29-
all_logs = stdout.decode("utf-8") + stderr.decode("utf-8")
30-
print("postgres container logs")
31-
print(all_logs)
28+
# wait for the postgres server to start
29+
for attempt in Retrying(
30+
stop=stop_after_delay(10), wait=wait_fixed(0.5), reraise=True
31+
):
32+
with attempt:
33+
stdout, stderr = container.get_logs()
34+
all_logs = stdout.decode("utf-8") + stderr.decode("utf-8")
35+
assert_that(all_logs).contains("server started")
3236
yield container
3337

3438

uv.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)