You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Pipeline执行pytest时出现Bash退出码5错误求助

修复方案

问题根源

pytest未收集到任何测试用例,且pytest-azurepipelines插件在无测试结果时返回错误码5,导致管道失败。

具体修复步骤:

  • 规范测试文件命名:pytest默认识别test_*.py或*_test.py格式的文件,确保你的测试文件符合该命名规则(避免命名为tests.py这类不符合规范的名称)。
  • 指定测试路径:如果测试文件不在当前工作目录或命名特殊,在pytest命令中明确指定路径。例如测试文件在tests目录下,修改脚本为:
    - script: |
        pip install pytest pytest-azurepipelines
        pytest tests/
      displayName: 'pytest'
    
    若为单个测试文件my_test.py,则用:
    - script: |
        pip install pytest pytest-azurepipelines
        pytest my_test.py
      displayName: 'pytest'
    
  • 允许无测试用例时不失败:如果你的场景允许无测试用例的情况,添加--no-fail-on-empty-suite参数让pytest不返回错误码:
    - script: |
        pip install pytest pytest-azurepipelines
        pytest --no-fail-on-empty-suite
      displayName: 'pytest'
    
  • 验证工作目录文件:在pytest步骤前添加目录检查命令,确认测试文件存在于当前工作目录:
    - script: |
        ls -la /home/vsts/work/1/s
      displayName: 'Check working directory contents'
    

内容的提问来源于stack exchange,提问作者Nintendo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 15:09:53