azure-devops - 在 Python 中合并来自多个 Azure Pipeline 作业的覆盖结果(使用 pytest)

标签 azure-devops azure-pipelines

我已将我的开源项目设置为使用 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/

相关文章:

azure - 如何使用Azure Pipeline构建语言版本 'preview'的.Net Core 5项目?

visual-studio - 在池XXX中找不到满足以下需求的代理 : visualstudio although vs2022 community is installed

azure - 是否可以将配置迁移工具与 Azure Devops 结合使用?动态365

azure - 在 Azure Devops 中部署具有多个 Webjobs 的 WebAPI 项目

azure - 如何通过控制台应用程序更新 Azure DevOps 上的文件

azure-devops - 查找非亲子故事的简单方法

azure - 在线构建服务器TFS

tfs - EXEC :EXEC(0, 0): 错误: 未找到: python2

asp.net-core - Azure 应用服务上的 500.31 ANCM 故障排除

Azure 组变量未选择我的 appsetting.json 文件变量