Skip to content

Testing and Quality.md

Kelsey Smuczynski edited this page Mar 24, 2026 · 1 revision

Testing and Quality

Test Layout

tests/
  unit/
  integration/
  transfers/
  features/          # BDD scenarios
  conftest.py        # Rebuilds schema, runs Alembic, syncs search triggers, seeds lexicon/parameter data

Root-level pytest files also cover API/resource behavior.


Safe Local Test Setup

source .venv/bin/activate
set -a; source .env; set +a
pytest -q

Important repo behavior:

  • tests/__init__.py forces POSTGRES_DB=ocotilloapi_test
  • Tests normalize POSTGRES_HOST=db to localhost when needed
  • tests/conftest.py rebuilds the schema, runs Alembic, syncs search triggers, and initializes lexicon/parameter data

Many tests assume a live Postgres/PostGIS database. Before running destructive or migration-heavy suites, confirm that your environment is pointing at the test database, not a dev or shared database.


BDD Tests

uv run behave tests/features --tags="@backend and @production and not @skip" --no-capture

A helper script, run_bdd.sh, syncs BDD feature files from the separate OcotilloBDD repo before running Behave.


CI Jobs

tests.yml currently runs:

  • Unit/API/integration pytest against a PostGIS service container
  • Behave BDD tests against a PostGIS service container

Formatting and Linting

Tool How It Runs
black Pre-commit hook; CI auto-commit on non-environment branches
flake8 Pre-commit hook; CI run on PRs
pre-commit Local install via pre-commit install

The pre-commit config runs black and flake8 focused on serious syntax/import/runtime categories.

Run everything locally before pushing:

pre-commit run --all-files

Quality Expectations

  • Run black and flake8 on all touched files before pushing
  • Run targeted validation for the modified area
  • Run broader validation if the change affects DB boot, migrations, deploy, or shared runtime setup
  • Keep tests deterministic and idempotent where possible

Clone this wiki locally