TS003: TestCoverage
Overview
| Property | Value |
|---|---|
| ID | TS003 |
| Name | TestCoverage |
| Group | tests |
| Severity | WARNING |
Description
Checks that test coverage meets a minimum threshold.
Test coverage helps ensure:
- Code paths are exercised by tests
- New code is tested before merge
- Critical functionality has verification
- Maintenance burden is identified
What it checks
The check runs pytest --cov and verifies:
- PASSED: Coverage meets or exceeds threshold (default 80%)
- FAILED: Coverage is below threshold (reports percentage)
- NOT_APPLICABLE: pytest-cov is not installed
How to fix
Install coverage tools
pip install pytest-cov
# or
uv add --dev pytest-covCheck current coverage
pytest --cov=my_package --cov-report=term-missingIncrease coverage
- Add tests for uncovered code: Focus on critical paths first
- Test edge cases: Handle error conditions and boundaries
- Test branches: Cover both if/else paths
Configure coverage
Add to pyproject.toml:
[tool.coverage.run]
source = ["src/my_package"]
branch = true
omit = [
"*/tests/*",
"*/__main__.py",
]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
"if __name__ == .__main__.:",
]
fail_under = 80
[tool.pytest.ini_options]
addopts = "--cov=my_package --cov-report=term-missing"Generate HTML report
pytest --cov=my_package --cov-report=html
# Open htmlcov/index.html in browserWhy WARNING severity?
This check is a WARNING because:
- Coverage thresholds vary by project
- Some code (e.g., CLI, error handling) is harder to test
- High coverage doesn’t guarantee quality tests
Configuration
Set coverage threshold
[tool.pycmdcheck]
coverage_threshold = 80 # percentSkip this check
[tool.pycmdcheck]
skip = ["TS003"]CLI
pycmdcheck --skip TS003