Home > Software design >  Unable to publish code coverage in azure pipelines
Unable to publish code coverage in azure pipelines

Time:04-27

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

CodePudding user response:

  • You need to generate the cobertura coverage report and it needs to be added in the configuration.
  • Replace the coverage.xml into cobertura-coverage.xml which follows below
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/cobertura-coverage.xml'
  • I have modified your code
- 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:
         testRunner: JUnit
         testResultsFiles: 'junit/**.xml'
         testRunTitle: 'Publish test results for ${{ parameters.projectName }}'
     - task: PublishCodeCoverageResults@1
       inputs:
         codeCoverageTool: Cobertura
         summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/cobertura-coverage.xml'

References

CodePudding user response:

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

  • Related