Search code examples
pythonunit-testingcode-coveragecoverage.pytest-coverage

python test coverage comparison with previous run


I am using coverage.py to check the code coverage of my unit tests, in form of html report.

coverage run -m pytest
coverage html

The report is pretty cool which shows the overall coverage % and the coverage % of individual .py file. Every time I finished some code changes I would re-run the coverage report to check if my unit test test cases can cover the new codes well. However, the issue is that I have to spot manually if any .py file has particularly low coverage.

Is there any way or existing tool I can use to compare the test coverage with previous/historical run? So that I can easily spot if any .py file has significantly dropped coverage.


Solution

  • This feature is not supported by coverage.py currently, but can be built outside of coverage.py

    codecov.io

    Services like codecov.io provide this feature

    diff-cover

    Projects like diff-cover highlight lines in your most recent change that are missing coverage.

    The diff-cover command line tool compares an XML coverage report with the output of git diff. It then reports coverage information for lines in the diff.