We run tests on each pull request in github.
It would be very cool if the coverage would be visible if you are looking at the changes of a pull request.
While looking at the diff in the PR review I would like to see which line was covered and which line not.
We use pytest and travis.
I found this: https://github.com/TheKevJames/coveralls-python But AFAIK this shows the coverage reports somewhere else, not in the "Files changed" tab of the PR.
This question is not about reaching a overall coverage of X percent. This question is about seeing which lines where covered and which lines where not covered.
You can achieve this using Github Actions and the Github Check runs API.
Generic flow of the Github Action workflow will be:
pytest
on the changed files and then generate coverage
report.coverage
report to annotate the commit.The generated report looks something like this:
I have created a repository : pytest-annotate-pr to demonstrate how this can be done. Note that, this is just a demonstration of how this can be done, and it's far from production ready. For example, this currently only works when a commit is pushed in a PR :) It does not work when branches are merged into main
. The above screenshot is from one of the PR raised against main
.
If you work on this and make a production ready workflow, please consider making it into a Github Action.