plasma-umass / slipcover

Near Zero-Overhead Python Code Coverage
Apache License 2.0
475 stars 17 forks source link

Support `coverage`'s `exclude_lines` setting #26

Open rec opened 2 years ago

rec commented 2 years ago

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!

jaltmayerpizzorno commented 2 years ago

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...

orsinium commented 1 year ago

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.

sigma67 commented 4 months ago

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
jaltmayerpizzorno commented 4 months ago

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.

LilyFoote commented 4 months ago

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.

jaltmayerpizzorno commented 4 months ago

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