4
votes

I'm following the tutorial at https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python?view=azure-devops.

Here is my azure-pipelines.yml file:

# 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'

Running the pipeline fails with the following error message.

Bash exited with code '5'.

I enabled system diagnostics to add debug messages to the log.

The error occurs in the pytest phase of the pipeline. enter image description here

The full log is available at https://github.com/michaelhochleitner/debug-azure-devops-python-pipeline/blob/master/log.txt.

How can I make the pipeline run without failing?

1
pytest reported collected 0 items.phd

1 Answers

2
votes

How can I make the pipeline run without failing?

Agree with phd, the issue comes cause 0 test items can be collected.

Check this detailed answer from cewing:

Pytest gathers tests according to a naming convention. By default any file that is to contain tests must be named starting with test_ and any function in a file that should be treated as a test must also start with test_.

So it's obvious that pytest command can't find any xx.py file whose name starts with test_. So for pytest, there's no available tests for it and this causes the 0 items collected=>Bash exited with code '5'.

I checked your tutorial above and reproduce same issue:

enter image description here

To resolve it and make the run succeed:

For me, I simply created a new test_anyname.py file with content(test_xx.py+test_xx method) below:

enter image description here

And my pipeline then run successfully without Bash exited with code '5':

enter image description here

So you should make sure at least one test item can be found, and the error would go away. Hope it helps :)