Merge python coverage files?

I am wondering if it is possible to merge coverage.xml files into 1 file to see the global report in the HTML output.

I have my unit/functional tests working as 1 command, and integration tests as the second command. This means that my scope for unit/functional tests overridden by unit tests .

It would be great if I had some solution for this problem, mainly by combining these files into 1 file.

+14
python unit-testing code-coverage coverage.py python-coverage
source share
5 answers

I found another solution. I used the combine function ( read here ) so I run my coverage as: coverage run -p , and then I do coverage combine .

It's all. It generates 1 combined report.

+16
source share

Cannot merge .xml files, but you can merge raw data files. Your workflow will look like this:

 $ COVERAGE_FILE=.coverage_func coverage run the_functional_tests.py $ COVERAGE_FILE=.coverage_inte coverage run the_integration_tests.py $ coverage combine $ coverage xml 
+16
source share

You can achieve the same result using the add option. Suppose you run coverage on three Python scripts. After the first cover, use -a to add.

 coverage run first.py coverage run -a second.py coverage run -a third.py 

Print report

 coverage report -m 

Output: Report

 Name Stmts Miss Cover Missing ---------------------------------------------- first.py 97 1 99% 95 second.py 1 0 100% third.py 10 0 100% ---------------------------------------------- TOTAL 108 1 99% 
+7
source share

If your source code is in a directory called my_project , you can also do this if you included pytest and pytest-cov in a virtual environment:

 pytest --cov-report html --cov=my_project unit_tests pytest --cov-report html --cov=my_project --cov-append functional_tests 

--cov-append will add functional test coverage information to the coverage file that was created when the unit tests were run.

0
source share

Use the -a option with the coverage coverage command. For example: coverage mileage -a test1.py This will add the results to an existing coverage file, confirm the same by running a coverage report.

-one
source share

All Articles