I wrote Integration test using pytest in my python Azure Function app project. It is an Azure function app project. It's working fine in my local but getting a No Module found error in Azure Pipeline.
My project structure is,
sampleApi
|
---- __init__.py
---- __run__.py
library
|
---- core.py
---- utils.py
---- azure-storage.py
tests
|
---- sources
|
-------- __init__.py # To store all mock data
---- test_one.py
---- test_two.py
---- test_three.py
azure-pipelines.yaml
requirements.txt
In the parent directory of Local, I am running pytest using the following command.
pytest --doctest-modules --junitxml=junit/test-results.xml tests
We are not using a Virtual environment on the Azure pipeline. We are directly using it on the agent. Please find the below Azure-pipeline.yaml script
In Azure pipeline(azure-pipelines.yaml),
name : Build Report Function
trigger:
branches:
include:
- Pytest_Pipeline
pool:
vmImage: 'ubuntu-18.04'
stages:
- stage: Build
displayName: Build Project
jobs:
- job: Build
displayName: Build & Test
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.8'
inputs:
versionSpec: 3.8
- script: |
python -m pip install --upgrade pip
pip install --target="$(System.DefaultWorkingDirectory)/.python_packages/lib/site-packages" -r requirements.txt
pip install pytest pytest-azurepipelines
# pip install -e .
displayName: 'Install dependencies'
- script: |
python -m pytest tests/
displayName: 'pytest'
I am getting the following errors,
##[error]7 test(s) failed, 0 test(s) collected.
==================================== ERRORS ====================================
_________________ ERROR collecting tests/test_one.py _________________
tests/test_one.py:3: in <module>
import pandas as pd
E ModuleNotFoundError: No module named 'pandas'
_________________ ERROR collecting tests/test_one.py _________________
But I already added pandas in requirements.txt and it's working fine in my function app.
requirements.txt,
azure-functions
pymongo
dnspython
Jinja2
pandas
numpy
azure-storage-blob
python-pptx
openpyxl
python-dotenv