Skip to content

chore(coverage): configure coverage tooling to handle unreachable code properly#1610

Open
kings9527 wants to merge 3 commits into
aio-libs:mainfrom
kings9527:fix-coverage-unreachable-code
Open

chore(coverage): configure coverage tooling to handle unreachable code properly#1610
kings9527 wants to merge 3 commits into
aio-libs:mainfrom
kings9527:fix-coverage-unreachable-code

Conversation

@kings9527

Copy link
Copy Markdown

Configure coverage.py exclude_also patterns for standard unreachable code paths (TYPE_CHECKING, NotImplementedError, AssertionError, Protocol classes, abstract methods, repr, if name == 'main').

Add 'tests/' to coverage source so dead code in test helpers is visible.

Add tests/ flag to Codecov with 100% target to catch dead test code early.

Annotate existing unreachable/functional-test-only paths with explicit pragma comments instead of relying on implicit branch coverage gaps.

Fixes #1490

…e properly

Configure coverage.py exclude_also patterns for standard unreachable code
paths (TYPE_CHECKING, NotImplementedError, AssertionError, Protocol
classes, abstract methods, __repr__, if __name__ == '__main__').

Add 'tests/' to coverage source so dead code in test helpers is visible.

Add tests/ flag to Codecov with 100% target to catch dead test code early.

Annotate existing unreachable/functional-test-only paths with explicit
pragma comments instead of relying on implicit branch coverage gaps.

Fixes aio-libs#1490
@gemini-code-assist

Copy link
Copy Markdown

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@github-actions

Copy link
Copy Markdown

Thanks for the contribution! Automated Claude review is disabled on fork PRs because GitHub Actions restricts the OIDC token on them. A maintainer can trigger a review by commenting @claude please review once they have had a chance to look at the PR.

Align the '- tests/' list item with 'paths:' key (6 spaces)
instead of over-indenting to 8 spaces. Matches the existing
indentation style used throughout the rest of the file.

Fixes CI failure: wrong indentation: expected 6 but found 8
@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.18%. Comparing base (3c3819e) to head (ccd3f34).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1610      +/-   ##
==========================================
+ Coverage   93.83%   94.18%   +0.34%     
==========================================
  Files          81       81              
  Lines        8440     8388      -52     
==========================================
- Hits         7920     7900      -20     
+ Misses        520      488      -32     
Flag Coverage Δ
no-httpx 91.08% <ø> (+0.26%) ⬆️
os-ubuntu-24.04 94.18% <ø> (+0.34%) ⬆️
os-ubuntu-24.04-arm 92.37% <ø> (+0.27%) ⬆️
python-3.10 92.35% <ø> (+0.27%) ⬆️
python-3.11 92.35% <ø> (+0.27%) ⬆️
python-3.12 92.35% <ø> (+0.27%) ⬆️
python-3.13 92.41% <ø> (+0.33%) ⬆️
python-3.14 94.11% <ø> (+0.28%) ⬆️
unittests 94.18% <ø> (+0.34%) ⬆️
with-awscrt 93.95% <ø> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

thehesiod
thehesiod previously approved these changes Jun 6, 2026
@thehesiod

Copy link
Copy Markdown
Collaborator

@claude review

@claude

claude Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Claude finished @thehesiod's task in 3m 57s —— View job


Review complete

  • Gather context and read changed files
  • Analyze PR diff and changed files
  • Run analyze-pr-feedback for open threads
  • Write review findings
  • Finalize

The direction of this PR is right — using # pragma: no cover on genuinely unreachable paths and configuring standard exclude_also patterns cleans up coverage noise properly. Coverage improved +0.34% with -52 reported lines. A few specific concerns below.

Medium: Comment-text patterns in exclude_also are non-standard and fragile

pyproject.toml lines 193-194:

"Used in functional tests only",
"used in functional tests",

coverage.py's exclude_also is designed for code patterns (like if TYPE_CHECKING, @abstractmethod), not comment text. While it technically works (coverage.py matches any text on a line, including comments), this is fragile: any future code line that coincidentally contains either phrase would silently drop out of coverage tracking without any # pragma: no cover annotation. The lines affected already have # pragma: no cover applied directly, making these two entries redundant. They should be removed.

Low: Redundant exclude_also entries

pyproject.toml lines 184-185:

"pragma: no cover",
"pragma: no branch",

# pragma: no cover is already handled natively by coverage.py's built-in exclude_lines default — adding it to exclude_also is redundant (though harmless). # pragma: no branch is a branch-level pragma handled separately by coverage.py, not a line exclusion, so it doesn't belong in exclude_also either.

Medium: Codecov tests: status check placement may be invalid

.codecov.yml lines 18-21:

status:
  project: false
  patch:
    default:
      target: auto
  tests:          # ← placed as sibling of "project" and "patch"
    paths:
    - tests/
    target: 100%

Per Codecov's YAML schema, coverage.status only accepts project, patch, and changes as top-level keys. Custom named status checks go inside project: or patch:, not alongside them. The current tests: block is likely silently ignored (Codecov doesn't surface an error for it). The intended form would be:

status:
  project:
    default:
      target: auto
    tests:
      paths:
        - tests/
      target: 100%

The Codecov report doesn't show a separate "tests" status check, which is consistent with the block being inactive.

Positive observations

  • The standard exclude_also patterns (if TYPE_CHECKING, @abstractmethod, class .*\bProtocol\):, raise NotImplementedError) are idiomatic and correct.
  • # pragma: no cover annotations are placed correctly on classes/methods that are exclusively used in functional tests not run in the unit suite.
  • The TOML regex escaping for "class .*\\bProtocol\\):" and "@(abc\\.)?abstractmethod" is correct.
  • uv.lock update is expected (harmless dependency refresh from the pyproject.toml source change).
  • raise NotImplementedError exclusion on BaseHTTPStubber._events is appropriate — it's an abstract sentinel that's never intended to be called.

Outcome: approved by thehesiod; no blocking issues, but the three points above are worth addressing before merge to avoid dead config (tests: status block) and fragile exclusions (comment-text patterns).

@thehesiod

Copy link
Copy Markdown
Collaborator

@kings9527 what do you think of the review?

@kings9527

Copy link
Copy Markdown
Author

Thanks for the review, @thehesiod. The points from @claude are solid—I'll address all three:

  1. Remove the fragile comment-text patterns from (those paths are already covered by annotations)
  2. Drop the redundant / entries from
  3. Fix the Codecov block placement under instead of as a sibling to /

Will push a follow-up commit shortly.

@kings9527

Copy link
Copy Markdown
Author

To clarify the three items from the review above (the backticks got mangled in the first comment):

  1. Remove "Used in functional tests only" and "used in functional tests" from exclude_also — these are comment-text patterns, not code patterns, and the relevant lines already have # pragma: no cover annotations.
  2. Remove "pragma: no cover" and "pragma: no branch" from exclude_alsocoverage.py handles these natively, so they are redundant there.
  3. Move the tests: block in .codecov.yml under project: instead of as a sibling to project/patch.

- Remove fragile comment-text patterns from exclude_also (redundant with pragma annotations)
- Remove redundant pragma entries from exclude_also (handled natively by coverage.py)
- Fix Codecov tests: block placement under project: instead of status sibling
@kings9527

Copy link
Copy Markdown
Author

Pushed the fixes in :

  • : removed all four flagged entries from — comment-text patterns and redundant pragma lines are gone
  • : moved block under so Codecov actually picks it up

Ready for another look.

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.

[TODO] Let coverage tooling handle unreachable code properly (and remove redundant/oudated bits)

2 participants