Add Statement and Branch coverage columns to index.html report#2085
Add Statement and Branch coverage columns to index.html report#2085nedbat merged 8 commits intocoveragepy:mainfrom
Conversation
|
Note about the On macOS CI, both
For example: and: This looks like a timing / threading issue specific to the free-threaded (nogil) builds and the tracer, rather than something caused by the HTML report changes in this PR. Locally, I ran: make testwith py313t, py314t, and py315t available via pyenv, and all test environments (including the t builds) passed: If it would be helpful, I’m happy to open a separate issue to track the test_coverage_stop_in_threads behavior on free-threaded builds, but I kept this PR focused on the HTML layout only. |
Yes, those tests are usually ok, but occasionally fail. An improvement would be welcome if you know what to do about them. |
|
Can you add some testing in test_results.py? We don't need separate tests for each property, but they should be covered by some test in there. |
|
I like the way this is going. I'd like to work on the CSS styling once it lands. |
Added tests in this commit:46105c6 |
|
I've addressed the feedback so far (naming + tests), I’ve also removed the draft status. |
|
Also, I wonder if we should add these new Results properties to the JSON report? I guess that could be a second PR. |
|
Thanks! Yes, I agree — adding these new Results properties to the JSON report would be useful. Once this PR is merged, I can open a follow-up PR for the JSON report. |
| """Return numerator/denominator for branch coverage.""" | ||
| return self.n_executed_branches, self.n_branches | ||
|
|
||
| def _percent(self, numerator: int, denominator: int) -> float: |
There was a problem hiding this comment.
Great, this was what I was thinking.
coverage/results.py
Outdated
| numerator, denominator = self.ratio_covered | ||
| if self.n_statements == 0: | ||
| return 100.0 | ||
| return self._percent(numerator, denominator) |
There was a problem hiding this comment.
I think we can make this simpler because if n_statements is zero, so is the denominator:
return self._percent(*self.ratio_covered). The star syntax will also simplify the other two pc_* properties.
There was a problem hiding this comment.
Thanks! Addressed in this commit: 8e88313
coverage/htmlfiles/coverage_html.js
Outdated
| const table_body_rows = table.querySelectorAll("tbody tr"); | ||
| const no_rows = document.getElementById("no_rows"); | ||
|
|
||
| const header_row = table.tHead ? table.tHead.rows[table.tHead.rows.length - 1] : table.rows[0]; |
There was a problem hiding this comment.
Why are we conditionalizing on tHead and tFoot? When won't the table have a head or a foot?
There was a problem hiding this comment.
Thanks! I've removed the unnecessary conditionalizing as suggested.
|
Thanks for all this, I'll merge this and make some adjustments. Let me know what name I should use to credit you in the changelog and contributors files. |
|
Thank you so much! Please credit me as: Ryuta Otsuka. |
|
This is now released as part of coverage 7.12.0. |

Summary
This PR adds two new columns — Statement Coverage and Branch Coverage — to the HTML coverage report layout.
These columns appear only when branch coverage is enabled (using the --branch option).
The goal is to provide a concrete basis for discussion in Issue #2081.
If these two columns are considered useful, this change could be merged as-is.
Changes
Preview
Before
After
Related Issue
Discussion base: #2081