11

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.

8
  • 2
    Erm, whats wrong with python coverage.py setup.py? Feb 24, 2014 at 15:21
  • Won't that generate coverage for setup.py and the setuptools modules?
    – Craig
    Feb 24, 2014 at 15:23
  • Nope, it should generate the results for all the files it uses, have you tried it so far? Feb 24, 2014 at 15:24
  • It generated coverage for everything. i.e. httplib and such.
    – Craig
    Feb 24, 2014 at 15:29
  • Maybe being able to setup inclusion/exclusions like with Bullseye would help.
    – Craig
    Feb 24, 2014 at 15:30

2 Answers 2

11

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
4

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/\*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.