'Activate test coverage for python code on Gitlab
I'm trying to create a .gilab-ci.yml
step to activate the gitlab's test coverage with pytest + pytest-cov.
Current unsuccessful snippet
I've tried:
.only-default: &only-default
only:
- merge_requests
stages:
- test
test-py:
stage: test
image: "python:3.8"
script:
- pip install -r requirements.txt
- python -m pytest -vvv src --cov-report xml --cov=src
artifacts:
reports:
cobertura: coverage.xml
Among other packages used for my project, the requirements.txt
file contains pytest and pytest-cov.
The associated pipeline outputted:
Uploading artifacts...
coverage.xml: found 1 matching files and directories
Uploading artifacts as "cobertura" to coordinator... ok id=858390324 responseStatus=201 Created token=6uBetoBX
But I'm unable to see the new feature in my MR.
Does anyone have a working solution to activate the option ?
Reference page
https://docs.gitlab.com/ee/user/project/merge_requests/test_coverage_visualization.html
Solution 1:[1]
Solution to this question can be found in the issue in the gitlab repo:
Solution 2:[2]
The documentation states that coverage.py is needed to convert the report to use full relative paths. The information isn’t displayed without the conversion.
So in your example, instead of:
- python -m pytest -vvv src --cov-report xml --cov=src
Do:
- python -m pytest -vvv src --cov=src
- coverage xml -o coverage.xml
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alex |
Solution 2 | TamaMcGlinn |