id | title | sidebar_label | tags | keyword | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
python |
Merge Unit Test Coverage Data |
Python |
|
|
import WhatAreKeployFeatures from './index.md'
Programming Language | Prerequisites |
---|---|
python | Python 3 and above coverage.py |
To get the coverage data for your unit tests:
coverage run --data-file=.coverage.unit test_program.py
Here, test_program.py is the unit test program you want to run, and --data-file is set to .coverage.unit becuase, by default, raw coverage data would be written to .coverage which is where coverage data for keploy tests is present, so to avoid overwritting we pass a new file through data-file flag.
Note: If you face any problems with running the coverage library, you can refer to the documentation for the same here
To combine the coverage from the unit tests, and Keploy's API tests we can use the command below:
coverage combine
Make sure to run this command before starting a new test run to avoid getting multiple coverage files.
Finally, to generate the coverage report for the test run, you can run:
coverage report
and if you want the coverage in an html file, you can run:
coverage html