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? Commented Feb 24, 2014 at 15:21
  • Won't that generate coverage for setup.py and the setuptools modules? Commented Feb 24, 2014 at 15:23
  • Nope, it should generate the results for all the files it uses, have you tried it so far? Commented Feb 24, 2014 at 15:24
  • It generated coverage for everything. i.e. httplib and such. Commented Feb 24, 2014 at 15:29
  • Maybe being able to setup inclusion/exclusions like with Bullseye would help. Commented 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
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.