refactor(test): share container fixtures across the integration and e2e suites
Why: - tests/e2e/ cannot reach fixtures defined in a per-boundary conftest, and `pytest_plugins` is only honoured in the root conftest. Changes: - move the Postgres/MinIO/Qdrant container fixtures into tests/support/containers.py and register it as a root plugin - fold MinIO bucket creation into `minio_settings`; an autouse fixture in a globally registered plugin would pull a container into unit runs - add a `postgres_settings` fixture so a component can be built from it directly Impact: - no behavior change; `pytest -m unit` still needs no Docker Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
from collections.abc import Iterator
|
||||
|
||||
import pytest
|
||||
from testcontainers.community.minio import MinioContainer
|
||||
|
||||
from src.config import MinioSettings
|
||||
from src.infrastructure.minio.client import create_client
|
||||
|
||||
_BUCKET = "test-source-files"
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def minio_container() -> Iterator[MinioContainer]:
|
||||
with MinioContainer() as container:
|
||||
yield container
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def minio_settings(minio_container: MinioContainer) -> MinioSettings:
|
||||
config = minio_container.get_config()
|
||||
# Pinned to IPv4 for the same reason as postgres_url (see
|
||||
# tests/integration/postgres/conftest.py): `localhost` resolves to `::1`
|
||||
# first, but Docker only publishes the mapped port on IPv4, so the
|
||||
# connection hangs instead of failing.
|
||||
endpoint = config["endpoint"].replace("localhost:", "127.0.0.1:")
|
||||
return MinioSettings(
|
||||
endpoint=endpoint,
|
||||
access_key=config["access_key"],
|
||||
secret_key=config["secret_key"],
|
||||
secure=False,
|
||||
bucket=_BUCKET,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def _ensure_bucket(minio_settings: MinioSettings) -> None:
|
||||
client = create_client(minio_settings)
|
||||
if not client.bucket_exists(minio_settings.bucket):
|
||||
client.make_bucket(minio_settings.bucket)
|
||||
Reference in New Issue
Block a user