Testing Structure
This document details the folder structure and organization of tests.
Mirror Pattern
Tests are organized to mirror the application structure. If a module exists in database/{module}/, a corresponding test folder should exist in tests/{module}/.
tests/
├── conftest.py # Shared fixtures + wiring (async client, db session, auth helpers)
├── docs/ # Templates/guidance for module test documentation
│ ├── readme.md
│ └── template.md
├── companies/ # Example module suite
│ ├── readme.md # Module test documentation (based on tests/docs/template.md)
│ ├── fixtures.py # Module fixtures only
│ ├── test_companies_data.py # Canonical payloads/builders/constants for this module
│ ├── test_<feature>_<scenario>.py
│ └── ...
├── users/
│ ├── readme.md
│ ├── fixtures.py
│ ├── test_users_data.py
│ └── ...
└── [other modules]/
File Naming
- Test Files:
test_<feature>_<scenario>.py(feature/scenario focused) ortest_<module>.pywhile suites are small. - Test Functions:
test_*(e.g.,test_create_entity,test_get_entity) - Fixtures:
fixtures.py(module-specific fixtures only; compose shared fixtures fromtests/conftest.py) - Data Helpers:
test_<module>_data.pyfor canonical payloads/builders/constants (named to avoid pytest discovery conflicts and to be easy to import cross-module).
Conftest Hierarchy
- Root
tests/conftest.py: Defines global fixtures likeclient(ASGI-boundhttpx.AsyncClient),db_session(async DB session), andauth_headers(authenticated request headers). - Module fixtures: Prefer
tests/{module}/fixtures.pyfor module-only factories/fixtures. Usetests/{module}/conftest.pyonly when a sub-suite needs local fixture wiring.
Documentation requirement (per-module readme.md)
The reference backend keeps a readme.md inside each tests/{module}/ directory, using tests/docs/template.md as the starting point. This ensures test intent, fixtures, and critical assertions stay discoverable as suites grow.