The suite was pure-logic only (R2 S2b deferred the DB lane). Add an opt-in `db` fixture (tests/conftest.py) that hands a test a real session against an ephemeral Postgres; schema is built with `alembic upgrade head` (the real prod schema needs the unaccent extension + unaccent_simple TS config that create_all can't provide, and this also proves the migration chain applies). Each test starts from a TRUNCATEd clean DB so tests that COMMIT — the whole point, for R6 S2's transaction work — don't leak. backend/docker-compose.test.yml wires an ephemeral tmpfs pg + the test image. When no Postgres is reachable (a plain `docker run`), the DB tests SKIP and the pure-logic lane is unchanged: 172 passed, 2 skipped. With the DB: 174 passed. test_db_lane.py smoke-proves commit round-trip + TRUNCATE isolation. The gate wiring (siftlode.sh) lands in the ops repo.
36 lines
1.3 KiB
YAML
36 lines
1.3 KiB
YAML
# DB-backed pytest lane (R6 S3b): 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. The pure-logic lane still runs WITHOUT this file
|
|
# (plain `docker run … python -m pytest` — DB tests skip when no Postgres is reachable).
|
|
#
|
|
# 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
|
|
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
|
|
volumes:
|
|
- ./:/app
|
|
working_dir: /app
|
|
command: python -m pytest
|