As far as I can tell, it isn't posible to exclude multiple lines with exclude_lines. If I am reading the code correctly, it uses the lines_matching function, which checks the regexes line-by-line
https://github.com/nedbat/coveragepy/blob/eb5d81a302693abc08508e6431392056cc5043c9/coverage/parser.py#L99-L115
My use-case is I want to exclude lines like
except ValueError:
assume(False)
where assume is from hypothesis. Simply excluding assume(False) doesn't work because it doesn't exclude the except. I don't want to exclude other except ValueError blocks in the codebase. I know I can rewrite this as except ValueError: assume(False) on a single line, but I would prefer not to as I don't like code that does that.
What I would like to do is to write something like
[report]
exclude_lines =
except ValueError:\n *assume\(False\)
Or if that can't work
[report]
exclude_lines =
except ValueError:(?=\n *assume\(False\))
Neither of these work presently. As far as I can tell this can only be excluded by manually putting # pragma: no cover on each instance.
As far as I can tell, it isn't posible to exclude multiple lines with exclude_lines. If I am reading the code correctly, it uses the
lines_matchingfunction, which checks the regexes line-by-linehttps://github.com/nedbat/coveragepy/blob/eb5d81a302693abc08508e6431392056cc5043c9/coverage/parser.py#L99-L115
My use-case is I want to exclude lines like
where
assumeis from hypothesis. Simply excludingassume(False)doesn't work because it doesn't exclude theexcept. I don't want to exclude otherexcept ValueErrorblocks in the codebase. I know I can rewrite this asexcept ValueError: assume(False)on a single line, but I would prefer not to as I don't like code that does that.What I would like to do is to write something like
Or if that can't work
Neither of these work presently. As far as I can tell this can only be excluded by manually putting
# pragma: no coveron each instance.