Reputation: 160
I'm trying to create a .gilab-ci.yml
step to activate the gitlab's test coverage with pytest + pytest-cov.
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 ?
https://docs.gitlab.com/ee/user/project/merge_requests/test_coverage_visualization.html
Upvotes: 4
Views: 3492
Reputation: 160
Solution to this question can be found in the issue in the gitlab repo:
https://gitlab.com/gitlab-org/gitlab/-/issues/285086
Upvotes: 2
Reputation: 3248
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
Upvotes: 0