Skip to content

Feature: Implements the treat-unmeasured-as-uncovered flag#581

Closed
aweidner wants to merge 3 commits intoBachmann1234:mainfrom
aweidner:unmeasured-as-uncovered
Closed

Feature: Implements the treat-unmeasured-as-uncovered flag#581
aweidner wants to merge 3 commits intoBachmann1234:mainfrom
aweidner:unmeasured-as-uncovered

Conversation

@aweidner
Copy link

It's possible for coverage files to omit lines from a diff entirely rather than indicating that they were not hit. This pull request introduces a new flag to allow optionally counting these occurrences towards uncovered lines.

Current behavior

This diff for example

diff --git a/some_file.py b/some_file.py
index b9f1ea0b4e..6de5313ab7 100644
--- a/some_file.py
+++ b/some_file.py
@@ -606,3 +606,6 @@ urlpatterns = [
         name="redirect_to_catalog",
     ),
 ]
+
+def uncalled_func():
+    print("Hello World")

Along with this fragment of coverage in the lcov xml format:

...
<lines ...>
    <line number="610" hits="1"/>
</lines>
...

In this example, line 611 appears in the diff, but does not appear at all in the coverage.xml file. When diff-cover is run against this combination, we get the following output

-------------
Diff Coverage
Diff: origin/main...HEAD, staged and unstaged changes
-------------
some_file.py (100%)
-------------
Total:   1 line
Missing: 0 lines
Coverage: 100%
-------------

Because only one line is in common between the diff and the coverage information. With the existing behavior, the xml file would need to contain hits="0" lines as such:

<lines ...>
    <line number="610" hits="1"/>
    <line number="611" hits="0"/>
</lines>

In order to detect all of the changes in the diff, not just the ones that were executed.

New behavior

This pull request proposes a new flag --treat-unmeasured-as-uncovered (I'm open to renaming this). When set, this flag detects any unmentioned non-whitespace lines in the diff as being uncovered and reports them. For the example above, the output is:

-------------
Diff Coverage
Diff: origin/main...HEAD, staged and unstaged changes
-------------
some_file.py (50.0%): Missing lines 611
-------------
Total:   2 lines
Missing: 1 line
Coverage: 50%
-------------

Existing behavior is unchanged when the flag is off, preserving the old functionality for anyone who does not opt-in.

@aweidner aweidner closed this Feb 20, 2026
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.

1 participant