I can't find the test coverage report

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.

Hi, you can see the report in your MR : try (!4) · Merge requests · Gabor Szabo / gl-try · GitLab

On the left, you can download it

1 Like

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:

  1. Publish the coverage into your job’s page your pipeline > jobs like this:

    Or in the MR page:

    You can do this either using the GUI

    or through .gitlab-ci.yml:
  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+\%)$/'
  1. Get the covered/uncovered lines in the changes tab in MR page like this:
    image

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.
test:
  image: python:3.9
  stage: test
  script:
    - echo "hello world!"
    - pip install pytest pytest-cov flask
    - pytest --cov=python/
    - coverage html -o index.xml
  coverage: '/^TOTAL.+?(\d+\%)$/'
  artifacts:
    paths: 
       - index.html

pages:
  stage: deploy
  script:
    - mkdir .public
    - cp index.html .public
    - mv .public public
  artifacts:
    paths:
      - public
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
1 Like

On the left? I see “Artifacts” on the right and that’s where I thought I can download the xml file. What am I missing?

Thanks.

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/

ha ha sorry i’m thinking right but my fingers write left :grinning_face_with_smiling_eyes:

1 Like

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”.

Oh. Strangely I don’t see that.

At least not in the default mode. If I switch to Side-by-side (in the gear icon) then I can see the green bars.

I can also see some green bars when I view the full file (“Show full file” via the 3 vertical dots)

Thanks.