xorsyst
xorsyst

Reputation: 8257

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?

Upvotes: 20

Views: 8754

Answers (2)

ahaywood
ahaywood

Reputation: 436

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.

Upvotes: 32

Sven Marnach
Sven Marnach

Reputation: 602355

Ned Batchelder's coverage.py has a feature to combine the results of multiple runs, which seems to be exactly what you are looking for.

Upvotes: 4

Related Questions