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?

oz123
  • 27,559
  • 27
  • 125
  • 187
Pranjal Mittal
  • 10,772
  • 18
  • 74
  • 99
  • How is your project arranged? Are all three files in the same folder? Have you tried explicitly excluding the tests? – jonrsharpe Feb 09 '15 at 08:40
  • Yes all the 3 files are in the same folder. (All 3 are files) – Pranjal Mittal Feb 09 '15 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. http://www.jeffknupp.com/blog/2013/08/16/open-sourcing-a-python-project-the-right-way/ – jonrsharpe Feb 09 '15 at 10:43

1 Answers1

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.

Jude Job
  • 3
  • 1
  • 4
Tom
  • 522
  • 3
  • 13
  • Okay this sort of works. I shuffled around the args to get a working command: coverage run --omit unit_tests.py unit_tests.py – Pranjal Mittal Feb 09 '15 at 10:43