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:
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
intocobertura-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
- Azure devops reportgenerator task can't find coverage.cobertura.xml
- Publish code coverage not finding coverage file in Azure DevOps
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