Files
siftlode/backend/docker-compose.test.yml
T

44 lines
1.8 KiB
YAML

# DB-backed pytest lane: an ephemeral Postgres + the test image, wired together so the
# `db` fixture (tests/conftest.py) has a real database. The whole thing is throwaway — the pg data
# lives in tmpfs (RAM) and nothing is persisted. A pure-logic run without this file is possible but
# must say so: `docker run -e SIFTLODE_TEST_REQUIRE_DB=0 … python -m pytest` (without it, a missing
# Postgres fails the run instead of skipping the DB tests).
#
# docker compose -f backend/docker-compose.test.yml up --build --abort-on-container-exit \
# --exit-code-from test
# docker compose -f backend/docker-compose.test.yml down -v
services:
testdb:
image: postgres:16-alpine
environment:
POSTGRES_USER: siftlode
POSTGRES_PASSWORD: siftlode
POSTGRES_DB: siftlode_test
tmpfs:
- /var/lib/postgresql/data # ephemeral + fast; the schema is rebuilt per run
# One database per pytest-xdist worker, each through the app's own pool (5 + 10 overflow): the default 100
# connections would run out at 8 workers.
command: ["postgres", "-c", "max_connections=300"]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U siftlode -d siftlode_test"]
interval: 1s
timeout: 3s
retries: 30
test:
build:
context: .
dockerfile: Dockerfile.test
depends_on:
testdb:
condition: service_healthy
environment:
DATABASE_URL: postgresql+psycopg://siftlode:siftlode@testdb:5432/siftlode_test
# This lane HAS a Postgres + ffmpeg, so the DB/ffmpeg tests must actually run here: conftest turns
# a would-be silent skip into a hard failure (SIFTLODE_TEST_REQUIRE_DB).
SIFTLODE_TEST_REQUIRE_DB: "1"
volumes:
- ./:/app
working_dir: /app
# Coverage is on demand, not in the gate: see docs/development.md.
command: ["python", "-m", "pytest", "-n", "auto"]