-
-
Notifications
You must be signed in to change notification settings - Fork 456
Description
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
Lines 99 to 115 in eb5d81a
def lines_matching(self, *regexes): | |
"""Find the lines matching one of a list of regexes. | |
Returns a set of line numbers, the lines that contain a match for one | |
of the regexes in `regexes`. The entire line needn't match, just a | |
part of it. | |
""" | |
combined = join_regex(regexes) | |
if env.PY2: | |
combined = combined.decode("utf8") | |
regex_c = re.compile(combined) | |
matches = set() | |
for i, ltext in enumerate(self.lines, start=1): | |
if regex_c.search(ltext): | |
matches.add(i) | |
return matches |
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.