Skip to content

Skip excluded functions in LCOV function totals - #2206

Merged
nedbat merged 3 commits into
coveragepy:mainfrom
TrapsterDK:fix-lcov-excluded-functions
Jun 27, 2026
Merged

Skip excluded functions in LCOV function totals#2206
nedbat merged 3 commits into
coveragepy:mainfrom
TrapsterDK:fix-lcov-excluded-functions

Conversation

@TrapsterDK

Copy link
Copy Markdown
Contributor

Fixes #2205.

Summary

  • Skip LCOV function records when a function region has no reportable statements after exclusions are applied.
  • Count FNF from emitted functions rather than all discovered function regions.
  • Add a regression test for an excluded @abstractmethod that raises NotImplementedError.

Details

Line records already respect report exclusions. Function records were still generated from all discovered function code regions, so a fully excluded abstract method could appear as FNDA:0 and reduce downstream LCOV function coverage even when the text report shows 100% line coverage.

This narrows each function region before emission and skips regions with n_statements == 0, matching the line-reporting behavior for fully excluded code.

Tests

  • .venv/bin/python -m pytest tests/test_lcov.py::LcovTest::test_excluded_functions -q -n 0
  • .venv/bin/python -m pytest tests/test_lcov.py -q -n 0

Comment thread coverage/lcovreport.py Outdated

outfile.write(f"FNF:{len(functions)}\n")
outfile.write(f"FNH:{functions_hit}\n")
if functions_found:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you sure we should omit these lines if no functions are found/hit? Wouldn't it be better to output FNF:0 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe you are correct, I also added a regression test to assert this behaviour.

@nedbat
nedbat force-pushed the fix-lcov-excluded-functions branch from 4a80c04 to d4e185a Compare June 27, 2026 16:20
@nedbat
nedbat merged commit 65979cc into coveragepy:main Jun 27, 2026
42 checks passed
@nedbat

nedbat commented Jul 2, 2026

Copy link
Copy Markdown
Member

This is now released as part of coverage 7.15.0.

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.

LCOV function records include functions excluded by report config

2 participants