SyntaxStudy
Sign Up
Python Code Coverage with pytest-cov
Python Beginner 3 min read

Code Coverage with pytest-cov

Coverage

Install pytest-cov to measure which lines are executed by your tests.

Example
# Install
pip install pytest-cov
# Run with coverage
pytest --cov=myapp --cov-report=html
# Enforce minimum coverage
pytest --cov=myapp --cov-fail-under=80
# .coveragerc
[run]
omit = */migrations/*, */tests/*, manage.py
[report]
show_missing = True
Pro Tip

Target critical business logic for 90%+ coverage; exclude migrations, settings, and configuration.