我已将我的开源项目设置为使用 Azure Pipelines 运行 CI,并且正在按照 how to test Python apps 上的 Azure 管道文档中的示例收集代码覆盖率。
这似乎工作得很好,但代码覆盖率统计似乎只从单个作业(随机)中获取测试结果。为了获得对我的项目的完整覆盖(例如,对于平台相关代码),我真的需要聚合所有测试作业的覆盖范围。
以下是我的管道中的相关任务:
- bash: |
source activate test_env
pytest xarray --junitxml=junit/test-results.xml \
--cov=xarray --cov-config=ci/.coveragerc --cov-report=xml
displayName: Run tests
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov'
配置 Azure 以显示此信息的正确方法是什么?
我试过将
--cov-append
添加到我的 pytest
调用中,但这似乎没有什么区别。
最佳答案
根据文档,当您从不同的作业运行多个测试时,每个作业后都会清理结果,因此如果您想将所有测试结果收集到一个地方,您必须将结果发布到工件并在所有测试作业结束时,您必须合并它们。
基本上每个测试你都会有:
- jobs:
- job: testjob1
steps:
- step1 -> run tests
- step2 -> publish job1 artifacts
- job: testjob2
steps:
- step1 -> run tests
- step2 -> publish job2 artifacts
....
- job: consolidate
steps:
- step1 -> downloadArtifacts
- step2 -> publish test results
最后,您需要一份工作来下载所有这些工件,它们会完全按照您的方式发布它们。引用:https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml
引用:https://docs.microsoft.com/en-us/azure/devops/pipelines/artifacts/pipeline-artifacts?view=azure-devops&tabs=yaml
关于azure-devops - 在 Python 中合并来自多个 Azure Pipeline 作业的覆盖结果(使用 pytest),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56776185/