Closed MathieuLamiot closed 2 months ago
I would add it as a default, without a flag. I think with the assumptions it will always be correct.
I'm gonna need a bit of time before I get to this. But I see it. Just a busy time this week.
This is pretty interesting. I feel a bit iffy about trying to interpret data not in the report. But this seems sensible.
The flag should be documented in the readme and ill need a few tests before I can merge this
Thank you for the feedback. I won't have time right now for the test but I'll try to do something about this in the upcoming weeks for sure!
@Bachmann1234 I added a readme paragraph, unit & integration tests. I also changed the param name to use - instead of _ to comply with other parameters.
I also added .venv to .gitignore. I hope it's OK
Let me know what you think! Also, can you make the CI run? the verify.sh is passing locally but just to be sure
Annoyingly my readme formatting check had some nitpicks, I made the suggestions that I think will fix these.
Pr looks good, once we get this merged ill try to get it out there asap.
Good catch, thanks. It should be good for the 2 feedbacks you shared now 👍
Alright. Let's merge this in. I'll get it released in the next day or so
Thank you! Try out https://pypi.org/project/diff-cover/9.2.0/
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: https://github.com/Bachmann1234/diff_cover/issues/270#issuecomment-1017563602, 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: