I am trying to get code coverage results to show up on the pipeline run summary tab. To debug this, I used a sample project with the following pipeline.yaml file:
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
displayName: 'Use Python 3.7'
- script: |
pip install -r requirements.txt
displayName: 'Install requirements'
- script: |
pip install pytest pytest-azurepipelines
pip install pytest-cov
pytest --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml
displayName: 'pytest'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFiles: '**/test-*.xml'
testRunTitle: 'Publish test results'
The output of the PublishTestResults task is (Edit: As pointed out by the answers, this has nothing to do with the problem since it merely reports the test upload but not the code coverage report upload):
Starting: PublishTestResults
==============================================================================
Task : Publish Test Results
Description : Publish test results to Azure Pipelines
Version : 2.180.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/test/publish-test-results
==============================================================================
/usr/bin/dotnet --version
5.0.301
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
Async Command Start: Publish test results
Publishing test results to test run '324'.
TestResults To Publish 1, Test run id:324
Test results publishing 1, remaining: 0. Test run id: 324
Published Test Run : https://dev.azure.com/.../Runs?runId=324&_a=runCharts
Async Command End: Publish test results
Finishing: PublishTestResults
So, it seems that everything works as expected. However, I do not get the results to display on the summary tab (and no code coverage tab appears): Screenshot of pipeline summary
Since I am running out of ideas what to try: Is this feature broken or did I do something wrong?
Edit: It has been suggested to add a PublishCodeCoverageResults-task. However, with the following at the end of the above yaml-file, it still does not work.
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
The output of the task is:
Starting: PublishCodeCoverageResults
==============================================================================
Task : Publish code coverage results
Description : Publish Cobertura or JaCoCo code coverage results from a build
2021-07-21T04:26:34: -reports:/home/vsts/work/1/s/**/coverage.xml
2021-07-21T04:26:34: -targetdir:/home/vsts/work/_temp/cchtml
2021-07-21T04:26:34: -reporttypes:HtmlInline_AzurePipelines
2021-07-21T04:26:35: Writing report file '/home/vsts/work/_temp/cchtml/index.html'
2021-07-21T04:26:35: Report generation took 0.5 seconds
Generated code coverage html report: /home/vsts/work/_temp/cchtml
Reading code coverage summary from '/home/vsts/work/1/s/coverage.xml'
Async Command Start: Publish code coverage
Publishing coverage summary data to TFS server.
Lines- 17 of 22 covered.
Branches- 0 of 0 covered.
Modifying Cobertura Index file
Publishing code coverage files to TFS server.
Uploading 8 files
Building file tree
Uploaded 0 out of 1,426,385 bytes.
Uploaded 1,426,385 out of 1,426,385 bytes.
Associating files
Total files: 8 ---- Associated files: 0 (0%)
File upload succeed.
Published '/home/vsts/work/_temp/cchtml' as artifact 'Code Coverage Report_1263'
Async Command End: Publish code coverage
Finishing: PublishCodeCoverageResults