Search code examples
pythoncode-coverage

How to preserve individual reports while generating a combined one using Coverage.py


I just started using Coverage.py. I have a couple of .py scripts and I need to generate the combined report regarding their code coverage. I also need to keep the individual report for each .py script. As I debug the code, I notice that for each script there is a .coverage file generated. The problem is that after I run the

os.system("coverage combine") os.system("coverage report -m") os.system("coverage html")

commands, the individual reports seem to go away. The combined report is generated. Is there any way to fix this? Thank you all in advance.


Solution

  • There isn't a way to keep the original reports. You should copy the files.

    PS: subprocess is better than os.system

    PPS: Coverage.py has an API, so you don't need to spawn processes at all.