Skip to content

Commit b6f541f

Browse files
committed
fix: eliminate testcontainers deprecation warnings
Migrate from DockerCompose to DockerContainer with explicit wait strategy: - Use LogMessageWaitStrategy instead of deprecated @wait_container_is_ready - Configure pytest to filter testcontainers internal deprecation warnings - Remove docker-compose.yml (no longer needed) The testcontainers library still uses deprecated decorators internally (in get_exposed_port and other methods), so we filter those warnings while using the recommended wait strategies in our code.
1 parent 293f99f commit b6f541f

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

libs/redis/pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ markers = [
100100
"compile: mark placeholder test used to compile integration tests without running them",
101101
]
102102
asyncio_mode = "auto"
103+
# Filter out testcontainers internal deprecation warnings
104+
# These come from testcontainers library's own code, not our usage
105+
# We're already using the recommended LogMessageWaitStrategy
106+
filterwarnings = [
107+
"ignore:The @wait_container_is_ready decorator is deprecated:DeprecationWarning:testcontainers",
108+
]

libs/redis/tests/conftest.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import os
2-
import subprocess
2+
from typing import Generator
33

44
import pytest
55

66
try:
7-
from testcontainers.compose import DockerCompose # type: ignore[import]
7+
from testcontainers.core.container import DockerContainer # type: ignore[import]
8+
from testcontainers.core.wait_strategies import ( # type: ignore[import]
9+
LogMessageWaitStrategy,
10+
)
811

912
TESTCONTAINERS_AVAILABLE = True
1013
except ImportError:
@@ -13,25 +16,33 @@
1316
if TESTCONTAINERS_AVAILABLE:
1417

1518
@pytest.fixture(scope="session", autouse=True)
16-
def redis_container() -> DockerCompose:
19+
def redis_container() -> Generator[DockerContainer, None, None]:
1720
# Set the default Redis version if not already set
18-
os.environ.setdefault("REDIS_VERSION", "edge")
19-
20-
try:
21-
compose = DockerCompose(
22-
"tests", compose_file_name="docker-compose.yml", pull=True
21+
redis_version = os.environ.get("REDIS_VERSION", "edge")
22+
redis_image = f"redis/redis-stack:{redis_version}"
23+
24+
# Use DockerContainer with explicit wait strategy instead of RedisContainer
25+
# to avoid deprecated @wait_container_is_ready decorator
26+
container = (
27+
DockerContainer(redis_image)
28+
.with_exposed_ports(6379)
29+
.with_env("REDIS_ARGS", "--save '' --appendonly no")
30+
.waiting_for(
31+
LogMessageWaitStrategy(
32+
"Ready to accept connections"
33+
).with_startup_timeout(30)
2334
)
24-
compose.start()
35+
)
36+
container.start()
2537

26-
redis_host, redis_port = compose.get_service_host_and_port("redis", 6379)
27-
redis_url = f"redis://{redis_host}:{redis_port}"
28-
os.environ["REDIS_URL"] = redis_url
38+
redis_host = container.get_container_host_ip()
39+
redis_port = container.get_exposed_port(6379)
40+
redis_url = f"redis://{redis_host}:{redis_port}"
41+
os.environ["REDIS_URL"] = redis_url
2942

30-
yield compose
43+
yield container
3144

32-
compose.stop()
33-
except subprocess.CalledProcessError:
34-
yield None
45+
container.stop()
3546

3647

3748
@pytest.fixture(scope="session")

libs/redis/tests/docker-compose.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)