pythoncode-coveragepython-coverage

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?


Solution

  • 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.