Reputation: 5028
In order to get 100% test coverage, I need to ignore some file(s) in python.
I searched the web and I found nosetests
which I don't want to use.
I also found that I can edit my .coveragerc
file and omit files and functions, when running my tests using intellij (with unittest framework), it didn't manage to use .coveragerc
file.
Any idea how to ignore / omit / exclude files during test coverage ?
How can I run the test using this file as a parameter ?
Upvotes: 15
Views: 10870
Reputation: 101
To add to proton's answer.
You can also use the # pragma: no cover
commenting specific clauses. You can comment every clause in a file to exclude the content of the file. This is more tedious but gives you finer control if you want to partially ignore a file.
Here is a link to the coverage.py project that discuses coverage exclusion in further detail: https://coverage.readthedocs.io/en/7.0.0/excluding.html
I would have commented on proton's answer instead of making a new answer, but I do not have enough reputation. More so, I would have suggested an edit, but there are too many pending edits and stack-overflow will not let me add another.
Upvotes: 3
Reputation: 1739
You can use this command in your .coveragerc file.
# .coveragerc
[report]
show_missing = True
omit =
junk/*
You include the path of files you want to omit under the omit command, for example, I want to omit every file in the junk folder hence my use of junk/*
.
Upvotes: 22