1

I am using unittest2 with coverage within a virtual environment which also contains my project.

When I run coverage report -m, the report shows several other files from lib/python3.5/site-packages/.

Because there are several files to exclude, it is tedious to try to exclude them from the command line each time I want to run the test and see the coverage report. That is why I choose to rely on the configuration file instead.

The documentation says I should do so in the .coveragerc file. However I can not see it. When I run pip show coverage and then ls -a path_to_coverage_directory I see config.py file instead. So excluded one file from testing and reporting from it by looking where is the option --omit and changed it from:

self._omit = None 

to:

self._omit = ['/home/begueradj/development/app/lib/python3.5/site-packages/unittest2/case.py']

I saved the configuration file and run the test as well as the coverage report again: I saw this file is not excluded.

What am I missing? How do you tackle with this?

Stephen Rauch
50.1k32 gold badges119 silver badges143 bronze badges
asked Mar 30, 2018 at 17:46

1 Answer 1

5

.coveragerc is a file in your project's local directory that indicates how coverage should treat that specific set of code. You should have something like the following:

myproject/
 - mycodefile1.py
 - mycodefile2.py
 - ...
 - .coveragerc

Where .coveragerc is in the directory where you're executing coverage and unittest from. It contains the following:

[run]
omit = 
 case.py
 

or maybe something like:

[run]
source = mycodefile*.py

You can combine source and omit to include entire directories of code while excluding specific files within those directories. All depends on what exactly your code layout looks like. See here for how you can specify code files.

Kenly
27k7 gold badges50 silver badges67 bronze badges
answered Mar 30, 2018 at 18:16
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.