Skip to content

Warn Unused Coverage Exclusion #1482

Closed as not planned
Closed as not planned

Description

@rmorshea

Is your feature request related to a problem? Please describe.

Consider a case where you exclude code from coverage reports because, for whatever reason, the code cannot be covered by your test suite. Then at some time in the future, you make changes that cause that same code to become covered. However, you forget that you've excluded this code from coverage and do not realize that you will not be notified if you later lose coverage in the effected area.

Describe the solution you'd like

It would be great to have a configuration option that behaved similarly to MyPy's warn_unused_ignore which, if true, emits a warning if a line or file contains a type: ignore comment even though the line contains no typing errors.

In the case of Coverage, the behavior of a warn_unused_exclude (defaults to false) options would be to, if true, emit a warning when a line or branch is excluded from coverage reports even though that line or branch is in fact fully covered.

Here are some complicating factors to consider...

  • For users who have customized exclude_lines, setting warn_unused_exclude to true could produce false-positive warnings. That is, when users exclude code from coverage it is either because they don't care whether those sections of code have coverage, or because they would like those sections to be covered, but were unable to for some reason - warn_unused_exclude may produce false-positive warnings in the former case. I don't think this rules out the idea of adding warn_unused_exclude because, for users that might be impacted by these false-positive warnings, they can leave warn_unused_exclude=false or re-work their exclude_lines patterns.
  • If warn_unused_exclude is true, all lines and branches must be checked for coverage even if pragma: no cover is declared so as to warn if those sections are covered despite the declared exclusion.

Describe alternatives you've considered

I don't believe there are any alternatives available that would solve the problem I described.

Activity

  1. nedbat commented on Oct 30, 2022

    @nedbat
    Member

    Thanks, this is an interesting idea.

    You are right that some people exclude lines from coverage not because the lines won't be run, but because they don't care if they are run or not. So warning that the excluded lines were run might be annoying noise for them. I don't know how to strike that balance though. It leads me to thinking that warn_unused_exclude could be a list of regexes which are the exclusions to warn about. Not many people would go to that much trouble, I expect.

    If warn_unused_exclude is true, all lines and branches must be checked for coverage even if pragma: no cover is declared so as to warn if those sections are covered despite the declared exclusion.

    We don't have to worry about that, because exclusions don't affect how code is measured, only how it's reported. So all lines and branches are already checked for coverage no matter how many exclusions there are.

    This feature has been requested before, in #251 and #619, and there's a related idea in #814. I'll close this as a duplicate, and we can continue the discussion on #251.

  2. added
    duplicate
    and removed on Oct 30, 2022
  3. changed the title [-]Warn Unused Coverage Excusion[/-] [+]Warn Unused Coverage Exclusion[/+] on Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions