问题描述
我正在尝试让代码覆盖率结果显示在管道运行摘要选项卡上。为了调试这个,我使用了一个 sample project 和以下 pipeline.yaml 文件:
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'
PublishTestResults 任务的输出是(编辑:正如答案所指出的,这与问题无关,因为它只报告测试上传而不是代码覆盖率报告上传) :
Starting: PublishTestResults
==============================================================================
Task : Publish Test Results
Description : Publish test results to Azure Pipelines
Version : 2.180.0
Author : Microsoft Corporation
Help : https://docs.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
所以,似乎一切都按预期进行。但是,我没有在摘要选项卡上显示结果(并且没有出现代码覆盖率选项卡): Screenshot of pipeline summary
因为我已经没有什么可以尝试的想法了:这个功能是坏了还是我做错了什么?
编辑: 已建议添加 PublishCodeCoverageResults 任务。但是,在上面的 yaml 文件末尾添加以下内容,它仍然不起作用。
- task: PublishCodeCoverageResults@1
inputs:
codeCoveragetool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
任务的输出为:
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,385 out of 1,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
解决方法
要查看代码覆盖率,我认为您需要添加任务 PublishCodeCoverageResults@1
,添加发布代码覆盖率结果任务。
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
Estension https://marketplace.visualstudio.com/items?itemName=dazfuller.pyunittest-task