Add expand_coverage_report option to for #270 #416
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Issue
This PR provides a work-around that fixes #270
The issue reported there is that diff data contains all modified lines, while most coverage tools report by statement and not lines.
As an example, let's take this code change:
Diff file will report line 431 as being changed.
However, most coverage tools will report lines 429, 430 and 435 being hit or not by test, but nothing for line 431.
As a result, the Violation reporters do not report line 431 has a violation, even if it does not run during tests.
But diff reports don't report line 430 has being changed. So in the end, this changes goes silent in the diff-cover analysis.
Fix implemented
Following this suggestion: #270 (comment), it seems most coverage reports use the line opening a statement as the reference. Also, untested statements are reported in the coverage files, with 0 hits (they are not just missing).
The implemented solution is to:
In the example above, line 431 is not in coverage.xml. But line 430 is, so we add line 431 in the data extracted from the XML report, with the same number of hits as 430.
Risks & limitations
Tests performed
I tested this PR on the example presented above (so in Python), and with other changes covered in the same file ; with:
pytest --cov=. --cov-report=xml
diff-cover coverage.xml --compare-branch=origin/develop --markdown-report diff-cover-report.md --exclude 'test*.py' --fail-under=50 --expand_coverage_report
When line 430 is not tested
and diff-coverage returns:
Diff Coverage
Diff: origin/develop...HEAD, staged and unstaged changes
saas/views.py (95.5%): Missing lines 431
Total: 22 lines
Missing: 1 line
Coverage: 95%
The markdown:
When line 431 is tested
and diff-coverage returns:
Diff Coverage
Diff: origin/develop...HEAD, staged and unstaged changes
saas/views.py (100%)
Total: 22 lines
Missing: 0 lines
Coverage: 100%
The markdown: