Python Coverage Reporting in Gitlab CI
In a Django project at Jet-Stream, I saw a Renovate merge request for the coverage library.
My initial thought was “huh? I don’t think we’re using this,” but a second later I saw the opportunity:
update the gitlab-ci.yml
definition to enable coverage reporting in Gitlab merge requests.
django-tests:
script:
- - ./manage.py test
+ - coverage run ./manage.py test
+ - coverage xml -o coverage.xml
+ artifacts:
+ reports:
+ coverage_report:
+ coverage_format: cobertura
+ path: coverage.xml
The coverage_report
keyword has no mention on the gitlab-ci.yml
documentation page,
but there is a guide for use with pytest
that mentioned the coverage_report
keyword and its use.