How can I get an incremental report on code coverage in Python?
By "incremental", I mean what has been the change in the covered lines since some "last" report, or from a particular Git commit.
I'm using unittest and coverage (and coveralls.io) to get the code coverage statistics, which work great. But I'm involved only with a part of the project, and at first I'm concerned with what my last commit has changed. I expected coverage to be able to show the difference between two reports, but so far have not found anything short of running textual diff on HTML output.
解决方案
Brief
pycobertura diff --format html --output cov_diff.html coverage_old.xml coverage_new.xml
Details
I use the following chain (coverage):
Generate coverage report:
python -m coverage run -m unittest
Output cobertura's XML format:
coverage xml --omit tests/* -o cover_old.xml
-- Modify code or checkout newer commit --
Generate coverage report:
python -m coverage run -m unittest
Output cobertura's XML format:
coverage xml --omit tests/* -o cover_new.xml
Generate diff: pycobertura diff --format html --output cov_diff.html coverage_old.xml coverage_new.xml