Skip to content

Apply --ignore-regex to the TOTAL row of diff reports - #202

Open
Eljees wants to merge 1 commit into
aconrad:masterfrom
Eljees:fix/ignore-regex-applies-to-diff-total
Open

Apply --ignore-regex to the TOTAL row of diff reports#202
Eljees wants to merge 1 commit into
aconrad:masterfrom
Eljees:fix/ignore-regex-applies-to-diff-total

Conversation

@Eljees

@Eljees Eljees commented Aug 27, 2026

Copy link
Copy Markdown

The problem

--ignore-regex filters files out of the body of a diff report, but the
TOTAL row is still computed over every file, so the totals disagree with
the rows printed above them. Ignoring everything makes it obvious:

$ pycobertura diff --ignore-regex ".*" tests/dummy.source1/coverage.xml tests/dummy.source2/coverage.xml
Filename      Stmts    Miss  Cover    Missing
----------  -------  ------  -------  ---------
TOTAL            -1      -4  +31.06%

The table is empty, and TOTAL still reports the numbers for the files that
were supposed to be excluded.

With this change:

$ pycobertura diff --ignore-regex ".*" tests/dummy.source1/coverage.xml tests/dummy.source2/coverage.xml
Filename      Stmts    Miss  Cover     Missing
----------  -------  ------  --------  ---------
TOTAL             0       0  +100.00%

Why this looks like a bug rather than intended behaviour

  • show already behaves the other way: Fix total values when ignore regex used #176 threaded ignore_regex into the
    total calculations for show and was released in 3.3.1, and
    test_text_report__with_ignore_regex pins that behaviour. diff was left
    out of that change.
  • The lower layer is already prepared for it: Cobertura.line_rate(),
    total_statements(), total_misses() and total_hits() all take
    ignore_regex. Only the CoberturaDiff counterparts do not.

The change

DeltaReporter.get_summary_lines() calls diff_total_statements(),
diff_total_misses() and diff_line_rate() without passing
self.ignore_regex, and those three (plus the _diff_attr helper behind
them) had no parameter to receive it. This threads ignore_regex through.

Because every delta format goes through the same get_summary_lines(), this
fixes the TOTAL row for text, csv, markdown, json, yaml and html at once.

Tests

One CLI test and two reporter tests. Without the production change they fail
on the numbers, not on the shape of the output:

E   AssertionError: assert '-1' == '0'
E   AssertionError: assert '-1' == '-3'
E   AssertionError: assert 'TOTAL  -1  -4  +31.06%' == 'TOTAL  0  0  +100.00%'
passed failed
master 187 0
new tests, without the fix 187 3
new tests, with the fix 190 0

I also checked that both halves of the change are load-bearing by breaking
each one on its own and confirming the same three tests go red: reverting the
three call sites in reporters.py gives 187/3, and reverting only the file
selection in _diff_attr gives 187/3 as well.

flake8 pycobertura/ and black --check --diff pycobertura/ (the two tox
gates) both pass.

--ignore-regex removes files from the body of a diff report, but the
TOTAL row is still computed over every file, so the totals do not match
the rows above them. With --ignore-regex '.*' the table is empty and
TOTAL still reads -1 -4 +31.06%.

DeltaReporter.get_summary_lines() calls diff_total_statements(),
diff_total_misses() and diff_line_rate() without passing
self.ignore_regex, and those three plus _diff_attr had no such
parameter to pass it to. The underlying Cobertura.line_rate(),
total_statements(), total_misses() and total_hits() already accept it.

This threads ignore_regex through, which fixes the TOTAL row for every
delta format (text, csv, markdown, json, yaml, html), since they all
share get_summary_lines(). The show command was given the same
treatment in aconrad#176.

Adds one CLI test and two reporter tests.
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