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?
1 Answer 1
.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.
Comments
Explore related questions
See similar questions with these tags.