I want to perform an api test. I send an image and I receive a json containing predictions. I created an app/api.py script that contains a method to send the image and receive the response.
I can't run my test, I get an error
I am positioned at the root of my project
λ python -m unittest test/test_api.py
ModuleNotFoundError: No module named 'test/test_api'
Project tree:
-app
-- api.py
-test
-- test_api.py
import unittest
from unittest.mock import Mock, patch
import os, sys
# Add the 'app' directory to the Python path
current_dir = os.path.dirname(os.path.abspath(__file__))
app_dir = os.path.join(current_dir, 'app')
sys.path.append(app_dir)
from api import API
class TestAPI(unittest.TestCase):
def test_api_call(self):
// create a mock
...
api = API()
with patch('requests.post', return_value=mock_response):
response = api.getPredFromImg(image_path)
// Assert
...
if __name__ == "__main__":
unittest.main()