Unit test reports and Test Coverage Visualization at the same time?

Hello,

Is it possible to generate both the Unit Test Report and the Test Coverage Visualization in the same job?

Something along the lines of…

run_unittests:
  stage: test
  image: ${ARTIFACTORY}/${READER_IMAGE}:${CI_PIPELINE_ID}
  script:
    - python -m coverage run --source=./reader -m pytest tests --junitxml=test_reports.xml
    - coverage report
    - coverage xml
  artifacts:
    when: always
    reports:
      junit: report_tests.xml
      cobertura: coverage.xml

However, after doing some research it appears that it is not possible to define two reports within the same artifact (junit and covertura)? Is my understanding correct that this would need to be split into two jobs (running the same test suite) in order to get both artifacts working correctly?

Thank you,

S

@mkserge - Thanks for posting and welcome to the forum!

I haven’t tried this out myself but will give it a go today. Do you have a public project you are attempting this on maybe?

-James H, GitLab Product Manager, Verify:Testing

@mkserge - It looks like it will work. You can see the setup in this .gitlab-ci.yml file and i’ve pasted the necessary bit below to make it work in python.

test_job:
  stage: test
  script:
    - pip install pytest pytest-cov
    - pytest --junitxml=report.xml --cov=src/
    - coverage xml
  artifacts:
    when: always
    reports:
      junit: report.xml
      cobertura: coverage.xml

I hope this helps!

-James H, GitLab Product Manager, Verify:Testing

1 Like

Thank you @jheimbuck_gl.

My apologies, you are right, it does indeed work. I am somewhat at a loss as to why I did not get it to work the first time, but everything now seems to be working properly on the exact same commit I was trying this on :man_facepalming:

Thank you again :slight_smile:

S

@mkserge Not a problem! It can take a minute or two for that coverage visualization to show up the first time. Glad to hear it’s working now!

-James H, GitLab Product Manager, Verify:Testing