首页 > 解决方案 > Microsoft azure devops python 管道失败,Bash 以代码“5”退出

问题描述

我正在关注https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python?view=azure-devops上的教程。

这是我的 azure-pipelines.yml 文件:

# Python package
# Create and test a Python package on multiple Python versions.
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/python

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'
strategy:
  matrix:
    Python27:
      python.version: '2.7'
    Python35:
      python.version: '3.5'
    Python36:
      python.version: '3.6'
    Python37:
      python.version: '3.7'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '$(python.version)'
  displayName: 'Use Python $(python.version)'

- script: |
    python -m pip install --upgrade pip
    pip install -r requirements.txt
  displayName: 'Install dependencies'

- script: |
    pip install pytest pytest-azurepipelines
    pytest
  displayName: 'pytest'

运行管道失败并显示以下错误消息。

Bash 以代码“5”退出。

我启用了系统诊断以将调试消息添加到日志中。

错误发生在管道的pytest阶段。 在此处输入图像描述

完整日志可在https://github.com/michaelhochleitner/debug-azure-devops-python-pipeline/blob/master/log.txt获得。

如何使管道运行而不会失败?

标签: pythongitazureazure-devopsazure-pipelines

解决方案


如何使管道运行而不会失败?

同意phd,问题来了,因为可以收集0个测试项目。

cewing检查这个详细的答案

Pytest 根据命名约定收集测试。默认情况下,任何包含测试的文件都必须以 test_ 开头,并且文件中应被视为测试的任何函数也必须以 test_ 开头。

所以很明显pytest命令找不到任何xx.py名称以.开头的文件test_。所以对于 pytest,没有可用的测试,这会导致0 items collected=> Bash exited with code '5'

我检查了你上面的教程并重现了同样的问题:

在此处输入图像描述

要解决它并使运行成功:

对我来说,我只是创建了一个新test_anyname.py文件,其内容(test_xx.py+ test_xx method)如下:

在此处输入图像描述

然后我的管道在没有以下情况下成功运行Bash exited with code '5'

在此处输入图像描述

因此,您应该确保至少可以找到一个测试项目,并且错误会消失。希望能帮助到你 :)


推荐阅读