Skip to content

Excluding multiple lines with exclude_lines #996

@asmeurer

Description

@asmeurer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions