2

I am new to using coverage.py. I used coverage run unit_tests.py which ran my tests. Then I used coverage report which generated the following coverage summary:

Name         Stmts   Miss  Cover
--------------------------------
cardnames       28      0   100%
dominion       458    210    54%
unit_tests     181      0   100%
--------------------------------
TOTAL          667    210    69%

Apart from including cardnames.py and dominion.py which I am trying to test inside unit_tests.py, the coverage report also includes the unit_tests.py file itself. (in the coverage calculation). How can I exclude this file from the report?

3
  • How is your project arranged? Are all three files in the same folder? Have you tried explicitly excluding the tests? Commented Feb 9, 2015 at 8:40
  • Yes all the 3 files are in the same folder. (All 3 are files) Commented Feb 9, 2015 at 10:40
  • 1
    You could consider restructuring the project, such that the tests are in a separate folder. This makes it easier to develop, test and distribute. See e.g. jeffknupp.com/blog/2013/08/16/… Commented Feb 9, 2015 at 10:43

1 Answer 1

1

From their documentation:

You can further fine-tune coverage.py’s attention with the --include and --omit switches (or [run] include and [run] omit configuration values). --include is a list of filename patterns. If specified, only files matching those patterns will be measured. --omit is also a list of filename patterns, specifying files not to measure.

So, scripting from the hip, the syntax would be something like coverage run --source=<files to be included> --omit=unit_tests.py unit_tests.py.

Sign up to request clarification or add additional context in comments.

1 Comment

Okay this sort of works. I shuffled around the args to get a working command: coverage run --omit unit_tests.py unit_tests.py

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.