Orange County Lettings - Tests and Coverage¶
This page explains how to run tests and measure coverage locally.
Test stack¶
pytest: test runnerpytest-django: Django integrationpytest-cov: coverage reporting
Run unit tests¶
Always ensure your virtual environment is active before running commands.
source venv/bin/activate
pytest
Run tests with coverage¶
coverage run -m pytest
coverage report
Generate HTML coverage report¶
pytest --cov=oc_lettings_site --cov=profiles --cov=lettings --cov-report=html
# Open HTML report
open htmlcov/index.html # macOS
# xdg-open htmlcov/index.html # Linux
Continuous integration tips¶
Use
--maxfail=1 -qlocally to fail fast.Keep coverage thresholds consistent across environments if you enforce minimums.
Troubleshooting¶
Make sure
DJANGO_SETTINGS_MODULEis correctly set (seepytest.ini).If database errors occur, run
python manage.py migratebefore tests.If the environment variable
ENV_MODEinfluences behavior, set it todevfor local tests.
Orange County Lettings