Testing Guide
Test suite configuration and best practices
The backend uses pytest with:
- pytest-django — Django integration
- pytest-factoryboy — factory_boy model factories
Test layout
Tests live colocated with the code they cover under apps/backend/lcmd_db/:
apps/backend/lcmd_db/tests/— project-wide fixtures and conftestapps/backend/lcmd_db/<app>/tests/— per-Django-app tests (e.g.core/tests/,registry/tests/)
Running tests
# All tests
cd apps/backend && uv run -- pytest . -v
# One file
cd apps/backend && uv run -- pytest lcmd_db/core/tests/test_something.py
# One test by name
cd apps/backend && uv run -- pytest lcmd_db/core/tests -k "test_api_users_me_authorized"The infra services (Postgres, MinIO) must be running — docker compose up -d before you run tests. See Quickstart.
Test Configuration
Factory Boy Setup
Test data factories are defined in factories.py:
- Generate model instances with default values
- Customize instance attributes as needed
- Reuse across multiple tests
Fixtures
Common test fixtures in fixtures.py:
- Shared test data
- Reusable resources
- Test environment setup
Best Practices
- Follow the test pyramid:
- 70% unit tests
- 20% integration tests
- 10% end-to-end tests
- Maintain high test coverage (90%+)
- Use descriptive test names
- Keep tests independent
- Mock external services