Search code examples
pythonazureazure-pipelinespytestcobertura

Unable to publish code coverage in azure pipelines


When running Pytest through an azure pipeline the pipeline fails on being able to publish the code coverage results, then after in the output of the pipeline you can see that the files are generated. it looks like the PublishCodeCoverageResults@1 task is running before the coverage reports can be generated. the test.yml file looks like below:

      - script: |
          python -m pytest src/ -v -o junit_family=xunit2 --junitxml=junit/test-results.xml --cov=src/ --cov-report=xml
        displayName: Run tests
      - task: PublishTestResults@2
        condition: succeededOrFailed()
        inputs:
          testResultsFiles: 'junit/**.xml'
          testRunTitle: 'Publish test results for ${{ parameters.projectName }}'
      - task: PublishCodeCoverageResults@1
        inputs:
          codeCoverageTool: Cobertura
          summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'

And this is a screenshot of the output from the pipeline: error output from pipeline

the error line is as follows:

##[error]Unable to process command '##vso[codecoverage.publish codecoveragetool=Cobertura;summaryfile=/agent/_work/116/s/coverage.xml;reportdirectory=/agent/_work/116/s/htmlcov;]' successfully. Please reference documentation (http://go.microsoft.com/fwlink/?LinkId=817296)

Any help would be greatly appreciated


Solution

  • issue is due to the pytest-azurepipelines library as seen here: https://github.com/tonybaloney/pytest-azurepipelines/issues/33

    adding the --no-coverage-upload to the end of the pytest line fixed the issue