slipcover icon indicating copy to clipboard operation
slipcover copied to clipboard

Support `coverage`'s `exclude_lines` setting

Open rec opened this issue 2 years ago • 6 comments

I wasn't accurate in a previous issue: this feature is also gating for my project.


In real-world programs, there are significant quantities of code within otherwise tested files which are deliberately not unit tested due to diminishing returns and finite resources.

coverage uses the exclude_lines configuration file setting to match lines and scopes not to be included in coverage, usually with a specific comment - docs.

This is informative when reading code, and it also gives a more useful measure of actual coverage.

This sounds harder than my previous issues, because of the fact it applies to scopes as well as single lines.


coverage has a ton of other features, several of which we do use, but IMHO these two are the most important.

Thanks again for a very promising library!

rec avatar Aug 24 '22 10:08 rec

Mmm, I wonder how coverage implements these... go through the source matching and collect the set of lines that match, excluding them? That would seem easier than matching in the AST...

jaltmayerpizzorno avatar Aug 26 '22 12:08 jaltmayerpizzorno

Mmm, I wonder how coverage implements these... go through the source matching and collect the set of lines that match, excluding them?

Yes, it's a regex on the raw line.

That would seem easier than matching in the AST...

It cannot be done using AST because the patterns in exclude_lines may contain comments. Even more, the default exclude_lines excludes the lines with # pragma: no cover comments.

orsinium avatar Feb 22 '23 15:02 orsinium

Semi-related, is there any way to exclude code blocks with pragma: no cover? It seems to only ignore the line that the no cover statement is on

if condition: # pragma: no cover
  print()  # will not be covered

sigma67 avatar Apr 19 '24 12:04 sigma67

Semi-related, is there any way to exclude code blocks with pragma: no cover? It seems to only ignore the line that the no cover statement is on

if condition: # pragma: no cover
  print()  # will not be covered

No, SlipCover doesn't currently support this, sorry.

jaltmayerpizzorno avatar Apr 22 '24 16:04 jaltmayerpizzorno

Being unable to exclude blocks is pretty much a blocker for me - I'd have to comment every line or live with a big reported regression in coverage, neither of which is desirable.

LilyFoote avatar Apr 25 '24 10:04 LilyFoote

I hear you, folks. I will work on this ASAP.

jaltmayerpizzorno avatar Apr 25 '24 23:04 jaltmayerpizzorno

Idk if you'd consider it part of this more general feature, but not counting stuff like if TYPE_CHECKING: blocks is also a blocker for me. I do have that as an explicitly exclude_lines for coverage, but (ditto with pragma: no cover, and assert_never) i wish it was just handled by default (and optionally turn-off-able)

DanCardin avatar Sep 30 '24 18:09 DanCardin