9

I am deploying Django application using Gitlab CI/CD and pytest for testing of code and pytest-cov for generating coverage report

My .gitlab-ci.yml

stages:
  - test
  - deploy

image: python:3.6

test:
  stage: test
  script:
    - pip install pipenv
    - pipenv install
    - pipenv run py.test src/
  artifacts:
    paths:
      - htmlcov/

pages:
  stage: deploy
  dependencies:
    - test
  script:
    - mv htmlcov/ public/
  artifacts:
    paths:
      - public
    expire_in: 30 days
  only:
    - master

staging:
  stage: deploy
  script:
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
    - dpl --provider=heroku --app=app-staging --api-key=$HEROKU_PRODUCTION_API_KEY
  only:
    - master

production:
  stage: deploy
  script:
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
    - dpl --provider=heroku --app=app-production --api-key=$HEROKU_PRODUCTION_API_KEY
  when: manual
  only:
    - master

Since repository is under a group namespace, the url to the coverage report is

https://<group>.gitlab.io/<repository>/

For coverage report,

[![coverage report](https://gitlab.com/<group>/<repository>/badges/master/coverage.svg?job=coverage)](https://<group>.gitlab.io/<repository>/)

But this is displaying Unknown

enter image description here

I have setup Test Coverage parsing regex for python

enter image description here

3

2 Answers 2

6

I know this is an old question, but this may help others see this question in the future. Except setting the Test Coverage parsing regex in the Settings, CI/CD page, you need to make sure the test coverage percent is printed somewhere in the CI's console log. The printed line should match the given regex. So, Gitlab can parse and save it as the code coverage percent.

I've answered with more detail the same question: Gitlab coverage badge always unknow

3

Your regex works for me in Gitlab.

I've had similar problems though, because just rerunning a job does not pick up new settings, and so you need to do a fresh commit to get the coverage to show up in the job output.

Not the answer you're looking for? Browse other questions tagged or ask your own question.