Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get combined code coverage over multiple runs of Python script

I've got a python program which is tested by running it several times with different inputs, and comparing the outputs against reference results.

I'd like to get code coverage of all the tests combined, so I can see if there are extra sets of inputs I should be using to get complete coverage. I've looked at the coverage module but can't work out how I can make it do this.

Any clues?

like image 448
xorsyst Avatar asked Feb 27 '14 17:02

xorsyst


People also ask

How do I merge coverage files?

You can merge coverage data from multiple runs with -a/--add-tracefile . If you want to merge coverage reports generated in different --root directories you can use the --json-base to get the same root directory for all reports.

What is code coverage in Django?

Code coverage is a simple tool for checking which lines of your application code are run by your test suite. 100% coverage is a laudable goal, as it means every line is run at least once. Coverage.py is the Python tool for measuring code coverage.


1 Answers

If running on the same machine, run it with the -a option, which accumulates coverage data across multiple calls.

Example:

coverage erase

coverage run -a <command> [arguments, ...]

coverage run -a <command> ... # repeat as many times as needed.

coverage report

coverage html

doc: http://coverage.readthedocs.org/en/latest/cmd.html#data-file

Hope this helps.

like image 154
ahaywood Avatar answered Oct 09 '22 20:10

ahaywood