Reputation: 7188
In some rare cases my methods can contain branches of code unreachable during testing (e.g. handling of some rare exceptions etc.)
I mean I have code that I'll never want to cover by tests. Is there a special type of comment/docstring/whatever to mark such code so it is clearly distinguishable from normal code and excluded from nose code coverage reports?
Upvotes: 2
Views: 1247
Reputation: 473893
According to coverage
documentation, you need to put a pragma: no cover
comment into the code:
Any line with a comment of “pragma: no cover” is excluded. If that line introduces a clause, for example, an if clause, or a function or class definition, then the entire clause is also excluded.
a = my_function1()
if debug: # pragma: no cover
msg = "blah blah"
log_message(msg, a)
b = my_function2()
You can also use coverage
configuration file and define exclude_lines
configuration parameter with the list of patterns to exclude from coverage. For example, to exclude all __repr__()
methods from being taking into account:
[report]
exclude_lines = def __repr__
Upvotes: 3