Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support coverage's exclude_lines setting #26

Open
rec opened this issue Aug 24, 2022 · 7 comments · May be fixed by #58
Open

Support coverage's exclude_lines setting #26

rec opened this issue Aug 24, 2022 · 7 comments · May be fixed by #58
Assignees
Labels
enhancement New feature or request

Comments

@rec
Copy link

rec commented Aug 24, 2022

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 rec changed the title Support .coveragerc's exclude_lines setting Support coverage's exclude_lines setting Aug 24, 2022
@jaltmayerpizzorno jaltmayerpizzorno added the enhancement New feature or request label Aug 26, 2022
@jaltmayerpizzorno
Copy link
Collaborator

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
Copy link

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
Copy link

sigma67 commented Apr 19, 2024

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
Copy link
Collaborator

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
Copy link

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
Copy link
Collaborator

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

@jaltmayerpizzorno jaltmayerpizzorno self-assigned this Apr 25, 2024
@DanCardin
Copy link

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 DanCardin linked a pull request Oct 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants