Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate coverage from setup.py

I have a setup.py that runs tests via the common test_suite: "tests" setting. What is the best way to generate coverage from here? I figured that by running setup.py via the coverage tool, it would include setup.py in its coverage reports?

I have a load_tests hook in my tests/init.py, which I thought would be a nice place to enable coverage, but even that is too early, since it would start coverage before tests. Then there is the setUpClass function, but that would involve modifying every single test to include another module to start and stop coverage from here. It all seems rather clunky.

like image 536
Craig Avatar asked Feb 24 '14 15:02

Craig


2 Answers

This will report coverage just for the module you want, assuming that you have a Python module "my_module" with all your .py files and other modules in it:

coverage run --source=my_module/ setup.py test
like image 191
José L. Patiño Avatar answered Nov 12 '22 07:11

José L. Patiño


Just need to apply the filter at report generation time instead of at run-time like Bullseye does:

coverage run ./setup.py test
coverage html --include=libgsync/\*
like image 29
Craig Avatar answered Nov 12 '22 06:11

Craig