Avoid testcontainers Redis deprecation warning in integration tests.
Use a local RedisTestContainer with wait strategies instead of the deprecated RedisContainer, and keep conftest focused on fixtures. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
co-authored by
Cursor
parent
3073bfbf50
commit
0096df78a5
@@ -1,16 +1,19 @@
|
||||
"""Integration tests configuration."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
from collections.abc import Generator
|
||||
|
||||
import pytest
|
||||
import redis
|
||||
import structlog
|
||||
import logging
|
||||
from minio import Minio
|
||||
|
||||
from testcontainers.redis import RedisContainer
|
||||
from testcontainers.minio import MinioContainer
|
||||
|
||||
from tests.integration.redis_container_test import REDIS_PORT, RedisTestContainer
|
||||
|
||||
collect_ignore = ["redis_container_test.py"]
|
||||
|
||||
MINIO_ACCESS_KEY = "minioadmin"
|
||||
MINIO_SECRET_KEY = "minioadmin"
|
||||
MINIO_BUCKET = "test-bucket"
|
||||
@@ -37,16 +40,16 @@ def configure_logging() -> None:
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def redis_container() -> Generator[str]:
|
||||
def redis_container() -> Generator[str, None, None]:
|
||||
"""Set up a Redis container for testing and yield the Redis URI."""
|
||||
# Start container
|
||||
container = RedisContainer(
|
||||
container = RedisTestContainer(
|
||||
image="redis/redis-stack:7.2.0-v0",
|
||||
)
|
||||
container.start()
|
||||
# Set environment variable for Redis URI
|
||||
redis_host = container.get_container_host_ip()
|
||||
redis_port = container.get_exposed_port(6379)
|
||||
redis_port = container.get_exposed_port(REDIS_PORT)
|
||||
redis_uri = f"redis://{redis_host}:{redis_port}"
|
||||
|
||||
yield redis_uri
|
||||
@@ -56,7 +59,7 @@ def redis_container() -> Generator[str]:
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def minio_container() -> Generator[dict[str, str]]:
|
||||
def minio_container() -> Generator[dict[str, str], None, None]:
|
||||
"""Set up a Minio container for testing and yield the Minio URI."""
|
||||
# Start container
|
||||
container = MinioContainer(
|
||||
@@ -86,7 +89,7 @@ def minio_container() -> Generator[dict[str, str]]:
|
||||
def set_environment_variables(
|
||||
redis_container: str,
|
||||
minio_container: dict[str, str],
|
||||
) -> Generator[dict[str, str]]:
|
||||
) -> Generator[dict[str, str], None, None]:
|
||||
"""Set environment variables needed for tests."""
|
||||
# Build environment variables dictionary
|
||||
env_vars = {"REDIS_URI": redis_container}
|
||||
@@ -103,7 +106,7 @@ def set_environment_variables(
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def raw_redis_client(redis_container: str) -> Generator[redis.Redis]:
|
||||
def raw_redis_client(redis_container: str) -> Generator[redis.Redis, None, None]:
|
||||
"""Provide a raw Redis client connected to the test Redis container."""
|
||||
# Connect client
|
||||
client = redis.Redis.from_url(
|
||||
@@ -119,7 +122,7 @@ def raw_redis_client(redis_container: str) -> Generator[redis.Redis]:
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def raw_minio_client(minio_container: dict[str, str]) -> Generator[Minio]:
|
||||
def raw_minio_client(minio_container: dict[str, str]) -> Generator[Minio, None, None]:
|
||||
"""Provide a raw Minio client connected to the test Minio container."""
|
||||
# Connect client
|
||||
client = Minio(
|
||||
|
||||
Reference in New Issue
Block a user