Rewrite test fixtures for Postgres CI #17
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/basketball-api!17
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "16-postgres-ci-testing-rewrite-test-fixture"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Replace per-file SQLite test databases with shared Postgres-backed fixtures in conftest.py. Add a
postgres:16-alpineservice container to Woodpecker CI so tests run against real Postgres in the pipeline.Changes
.woodpecker.yaml— Addedservices:block withpostgres:16-alpinecontainer; setBASKETBALL_DATABASE_URLenv var in test steptests/conftest.py— Rewritten with shared fixtures:engine,setup_db(autouse, create/drop per test),db(session),tenant(seeded tenant),client(TestClient withget_dboverride)tests/test_register.py— Removed module-level SQLite engine/session/setup/teardown; now uses conftest fixtures via pytest injectiontests/test_coach.py— Removed module-level SQLite engine/session; now uses conftest fixtures; keptcoachfixture local to this moduletests/test_models.py— Removed module-level SQLite engine/session/setup/teardown; now uses conftest fixturesTest Plan
pytestagainst the Postgres service containerruff check .andruff format --check .passReview Checklist
src/application code modified — test infrastructure onlyruff check .passesruff format --check .passespostgres:16-alpineRelated
PR #17 Review
BLOCKERS
None. The code is correct and well-structured.
NITS
test_register.py_seed_tenantfixture body is empty. The fixture depends ontenant(which seeds it), so the empty body is functionally correct. However, adding a one-line docstring body or apasswould make it clearer that the fixture exists solely to pull in thetenantdependency. Currently it has a docstring but noyieldorpass-- this works because docstrings are valid function bodies in Python, but ayieldwould make the autouse lifecycle explicit.conftest.pymodule-levelengineandTestSessionare created at import time. This means theBASKETBALL_DATABASE_URLenv var must be set beforeconftest.pyis imported, which it is (viaos.environ.setdefaultat the top of the file before thesettingsimport). This is correct but fragile -- any future conftest refactoring that reorders imports could break it. The# noqa: E402comments acknowledge this. Not blocking, just worth noting for future maintainers.Woodpecker service container has no healthcheck or readiness wait. The
postgres:16-alpineservice container may not be ready whenpyteststarts. Postgres typically starts fast enough that this is not an issue in practice, but if CI flakes appear, addingpg_isreadyto the commands beforepytestwould fix it. Example:apt-get update && apt-get install -y postgresql-client && pg_isready -h postgres -U basketball -d basketball_test --timeout=30.SOP COMPLIANCE
16-postgres-ci-testing-rewrite-test-fixturereferences #16)Closes #16src/modifications@patchdecorators on all Stripe calls)BASKETBALL_DATABASE_URLenv var matches app config (env_prefix = "BASKETBALL_"+ fielddatabase_urlin/home/ldraney/basketball-api/src/basketball_api/config.py)dbfixture usestry/finally/session.close(),setup_dbdrops all tables after each testservices:block withname,image,environment)VERDICT: APPROVED