Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Coverage - Analyze only project files

I'm using coverage module in python to check the code coverage. However, while running 'coverage report', the module is analyzing unwanted files shown below other than the project files.

covering unwanted files

How can I remove unwanted files from executing in coverage report?

like image 239
Tony Mathew Avatar asked Oct 21 '25 12:10

Tony Mathew


2 Answers

The simplest way is to use --source=. so that it will only consider files in the current directory.

like image 142
Ned Batchelder Avatar answered Oct 23 '25 01:10

Ned Batchelder


You should use --omit flag to exclude the unwanted files. The RegEx is allowed to use. Eg.: coverage run --omit "*/app/*,*__init__*,*_ut.py" You can see more details: https://coverage.readthedocs.io/en/v4.5.x/source.html

like image 33
milanbalazs Avatar answered Oct 23 '25 03:10

milanbalazs