Code coverage measures how much of a program’s code a test suite executes, usually as a percentage. It helps reveal untested areas and evaluate test effectiveness, but high coverage does not guarantee bug-free software. section 6.4
A practical Python coverage workflow is:
- Install the coverage library with pip install coverage. section 6.4
- Run the test suite and collect data with coverage run -m pytest. section 6.4
- Review a text report with coverage report or generate an HTML report with coverage html in the htmlcov directory. section 6.4
- Use low coverage to identify code needing more tests; 70% is a starting point, while teams may aim higher. section 6.4
Running coverage for a Python project
pip install coverage coverage run -m pytest coverage report coverage html The resulting report shows coverage for each project file and highlights areas that tests do not exercise. section 6.4
Figure 6.3 The code coverage report showing the coverage for each file in our ITAM system project
Inspect the file-by-file coverage report for an IT asset management project. section 6.4













