Skip to content

Coverage: exclude some noise #656

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

Merged
merged 2 commits into from
Aug 24, 2025

Conversation

brianschubert
Copy link
Member

Going through the current test coverage results, there's quite a bit of noise from things that are not expected to be executed or would not be meaningful to test. For example, dummy functions with placeholder bodies:

def __buffer__(self, flags: int) -> memoryview:
return memoryview(b'')

and unexpected error handling:

try:
proc = subprocess.run(
[sys.executable, "-c", code], check=True, capture_output=True, text=True,
)
except subprocess.CalledProcessError as exc:
print("stdout", exc.stdout, sep="\n")
print("stderr", exc.stderr, sep="\n")
raise

It would be nice to exclude these from the coverage report so that it's easier to see what's actually missing coverage.

This PR adds exclusions for:

  • pass and raise NotImplementedError used as placeholder bodies (via pyproject.toml config)
  • various ad-hoc placeholder bodies in the tests (via # pragma: no cover comments)
    • (another option would be to normalize these bodies to some common form that can be more easily excluded en-masse, like raise NotImplementedError or ...)
  • two other cases which don't seem meaningful to test, namely the if __name__ == '__main__' block in the tests and the __repr__ of an internal sentinel

@brianschubert
Copy link
Member Author

@@ -165,7 +165,7 @@


class _Sentinel:
def __repr__(self):
def __repr__(self): # pragma: no cover
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine but maybe we should eat our dogfood and use typing_extensions.Sentinel.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if not, we could also just add a test for this. I know it's trivial code, but it doesn't really do any harm to test it explicitly, and it's nice to keep pragma: no cover exclusions to a minimum.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dogfooding Sentinel sounds neat - I opened #657 to give that a try

@JelleZijlstra JelleZijlstra merged commit 4bd67c5 into python:main Aug 24, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants