I am using Azure Pipelines and getting the following error:
ImportError: Failed to import test module: QueryUrls
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.8.3/x64/lib/python3.8/unittest/loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "/home/vsts/work/1/s/QueryUrls/__init__.py", line 2, in <module>
import azure.functions as func
ModuleNotFoundError: No module named 'azure'
The error occurs when I run unit tests for an Azure Function written in Python. The code I am runnning in the pipeline (to run the unit tests) is the following:
- script: |
python -m unittest QueryUrls/test_queryurls.py
displayName: 'Test with unittest'
The pipeline was running correctly before I added the above lines. Here is the script that is being called:
# tests/test_httptrigger.py
import unittest
from pathlib import Path
import azure.functions as func
from . import main
#from QueryUrls import my_function
class TestFunction(unittest.TestCase):
def test_my_function(self):
# Construct a mock HTTP request.
req = func.HttpRequest(
method='GET',
body=None,
url='/api/QueryUrls',
params={'name': 'World'})
# Call the function.
resp = my_function(req)
# Check the output.
self.assertEqual(
resp.get_body(),
b'Hello World',
)
if __name__ == '__main__':
unittest.main()