| name | backend-testing |
| description | Mandatory standard operating procedure for running tests in the Divemap backend. Explicitly forbids direct pytest commands that cause data loss and explains SQLite incompatibility. |
🚨 DANGER: Backend Testing Protocol 🚨
Divemap uses an isolated Docker MySQL test environment. DO NOT run pytest directly inside the backend container or virtual environment.
The test suite contains a teardown step (Base.metadata.drop_all(bind=engine)) that WILL wipe out the entire development database if it runs against the live connection string.
The ONLY Permitted Testing Method: Isolated Docker MySQL
- How: Executing
backend/docker-test-github-actions.sh [path/to/test.py]
- What it does: Completely tears down and rebuilds an isolated Docker network with a real MySQL 8.0 container and a fresh Python container. It runs Alembic migrations from scratch to build the schema safely.
- Pros: Guarantees production parity. Protects the live development database from being dropped. Catches MySQL-specific syntax errors.
- Cons: Slower than raw pytest (~10-20s startup), but strictly necessary for safety.
Standard Operating Procedure
- NEVER RUN
pytest DIRECTLY:
- ❌
docker-compose exec backend pytest -> FORBIDDEN. WILL WIPE DATABASE.
- ❌
cd backend && ./divemap_venv/bin/pytest -> FORBIDDEN. SQLite is incompatible and will crash.
- ✅
cd backend && ./docker-test-github-actions.sh -> SAFE AND REQUIRED.
- Why SQLite is Unsupported:
Divemap uses native MySQL features like Spatial Data Types (
POINT) and LONGTEXT. Because the test suite builds the schema from scratch using Base.metadata.create_all, any attempt to run pytest against SQLite will fail immediately with a CompileError.
- Debugging
docker-test-github-actions.sh:
- Preventing Database Wipes: A hard fail-safe has been added to
conftest.py that will abort the test suite if it detects the live database URL. However, you must still adhere to this protocol.
Quick Reference Commands
| Goal | Command |
|---|
| Run Specific Test (Safe) | cd backend && ./docker-test-github-actions.sh tests/test_file.py |
| Debug Full DB Test (Verbose) | cd backend && ./docker-test-github-actions.sh -v tests/test_file.py |
| View Test Output | cat backend/test-failures.txt |