I am trying to figure out how to see the test coverage report. I have this public repo. I think I configured it properly, but I don’t know where can I see the integrated coverage report.
If I enabled the
paths:
- htmlcov
in the pipeline, I could then download the HTML report generated and I could even see it on GitLab, but as I understand there is also an integrated reporting tool that uses the xml file that was generated.
in the pipeline, I could then download the HTML report generated and I could even see it on GitLab, but as I understand there is also an integrated reporting tool that uses the xml file that was generated.
There are two things:
Publish the coverage into your job’s page your pipeline > jobs like this:
script:
- pip install pytest pytest-cov flask
- pytest --cov=echo_get --cov-branch
- coverage xml -o coverage.xml
# You add this regex to extract the total coverage from the pytest output
coverage: '/^TOTAL.+?(\d+\%)$/'
Get the covered/uncovered lines in the changes tab in MR page like this:
This is done by adding the artifact:reports:coverage.xml. What you have in your .gitlab-ci.yml should work but for some reason it doesn’t.
I tried many combinations on your repo, but nothing seems to work. Maybe there an issue with how you write your test and how you run them (I am not a pytest expert, and it’s been a while since I wrote python code), or maybe (least probable) there is a bug in gitlab ci and how it handles python.
Bonus:
You can export the html report as an html file (with artifacts:paths) and publish it as a gitlab page (the drawback is that pages should be public). All you have is to add another job to publish the html file.
I managed to add the TOTAL % to the job by also using --cov-report term, but I still don’t know how to get the coverage on the diff.
In any case I think the coverage report on the diff can be very misleading. What if I changed a test (e.g. commented out a test-case) that will eliminate some test from code that has not been changed.
That would be totally invisible in such report.
What I would really like is a full coverage report of all the source code and the change of test coverage between runs. I guess I still need to use something like https://coveralls.io/
I see the test coverage on your diff. There are a few green bars between the line numbers and the actual content of the lines. If I hover over them I can see “Test coverage: 1 hit”.