I am using coverage.py to get the test coverage of the code.
Suppose I have two functions with the same name in two different modules
# foo/foo.py
def get_something():
# fetch something
# 10 line of branch code
return "something foo/foo.py"
# bar/foo.py
def get_something():
# fetch something
# 20 line of branch code
return "something bar/foo.py"
How can I exclude the bar.foo.get_something(...)
function "completely" ?
You can exclude them all at once without littering your code with exclusion pragmas. If the matched line introduces a block, the entire block is excluded from reporting. Matching a def line or decorator line will exclude an entire function.
Edit Configurations > Select Code Coverage tab > then adding the package or class I want to be excluded or include only in the code coverage report.
The easiest way to exclude code from code coverage analysis is to use ExcludeFromCodeCoverage attribute. This attribute tells tooling that class or some of its members are not planned to be covered with tests. EditFormModel class shown above can be left out from code coverage by simply adding the attribute.
You'll have to specify in omit **/tests/* to ignore nested test folders.
We can use pragma
comment on the function definition level which tells the coveragepy to exclude the function completely.
# bar/foo.py
def get_something(): # pragma: no cover
# fetch something
# 20 line of branch code
return "something bar/foo.py"
If we have the coveragepy config file with an exclude_lines
setting in it, make sure that pragma: no cover
in that setting because it overrides the default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With