'Append pytest coverage to file in Gitlab CI artifacts

I am trying to split my pytests in a gitlab stage to reduce the time it takes to run them. However, I am having difficulties getting the full coverage report. I am unable to use pytest-xdist or pytest-parallel due to the way our database is set up.

Build:
  stage: Build
  script:
    - *setup-build
    - *build
    - touch banana.xml   # where I write the code coverage collected by pytest-cov
    - *push
  artifacts:
    paths:
    - banana.xml
    reports:
      cobertura: banana.xml

Unit Test:
  stage: Test
  script:
    - *setup-build
    - *pull
    - docker-compose run $DOCKER_IMG_NAME pytest -m unit --cov-report xml:banana.xml --cov=app --cov-append;
  needs:
    - Build

Validity Test:
  stage: Test
  script:
    - *setup-build
    - *pull
    - docker-compose run $DOCKER_IMG_NAME pytest -m validity --cov-report xml:banana.xml --cov=app --cov-append;
  needs:
    - Build

After these two stages run (Build - 1 job, Test - 2 jobs), I go to download the banana.xml file from Gitlab but there's nothing in it, even though the jobs say Coverage XML written to file banana.xml

Am I missing something with how to get the total coverage written to an artifact file when splitting up marked tests in a gitlab pipeline stage?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source