I am trying to run python unit tests in the azure DevOps pipeline using pytest, but it's giving the error below
here is the yml code
trigger:
- main
- test-unit-test-devops
jobs:
- job: Test
pool:
name: OnPrem //private pool
demands:
- Agent.OS -equals Linux
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.9.5'
addToPath: true
architecture: 'x64'
- task: Bash@3
inputs:
targetType: 'inline'
script: |
python -m pip install --upgrade pip
pip install -r requirements.txt
workingDirectory: '$(Build.SourcesDirectory)'
displayName: "Installing Dependencies"
- task: Bash@3
inputs:
targetType: 'inline'
script: pytest
workingDirectory: '$(Build.SourcesDirectory)'
displayName: "Run all unit tests"
the pipeline is passing all the above tasks except the "Run all unit tests" task, my folder structure is this
<project_root>/
| - .venv/
| - .vscode/
| - add_pipeline_config/
| | - __init__.py
| | - function.json
| | - example.py
| - my_second_function/
| | - __init__.py
| | - function.json
| - tests/
| | - test_add_pipeline_config.py
| - .funcignore
| - host.json
| - local.settings.json
| - requirements.txt
| - Dockerfile
I did try the following fixes but the error still persists
- Added/Removed init.py from the tests folder
- tried these scripts to run the test
- pytest
- python -m pytest
- python -m pytest/pytest
- setting PYTHONPATH to $(Build.SourcesDirectory)
- creating & activating python virtualenv
I have also checked source dir by printing the $(Build.SourcesDirectory) which is /azp/_work/1/s and i can see my files inside this directory
Note: The error doesn't occur on my local machine. The error occurs only on azure devops
Could someone point out what am I doing wrong...would really appreciate