slipcover
slipcover copied to clipboard
Support `coverage`'s `exclude_lines` setting
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!
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...
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.
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
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 onif condition: # pragma: no cover print() # will not be covered
No, SlipCover doesn't currently support this, sorry.
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.
I hear you, folks. I will work on this ASAP.
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)