Вопрос: Как исправить оператор импорта в моем тестовом файле?
===============================================
Я запускаю следующие команды:
команды длязапустить тесты
cd cluster_health
python -m pytest tests/ -v -s
Я получаю следующую ошибку!
ImportError while importing test module '<full path>...\cluster_health\tests\unit\test_handler.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests\unit\test_handler.py:5: in <module>
from health_check import app
health_check\app.py:3: in <module>
import my_elastic_search
E ModuleNotFoundError: No module named 'my_elastic_search'
. \ cluster_health \ tests \ unit \ test_handler.py
import json
import sys
import pytest
import health_check
from health_check import app
from health_check import my_elastic_search
# from unittest.mock import patch
import mock
from mock import Mock
def test_lambda_handler(apigw_event, monkeypatch):
CONN = Mock(return_value="banana")
monkeypatch.setattr('health_check.my_elastic_search.connect', CONN)
ret = app.lambda_handler(apigw_event, "")
# etc...
. \ cluster_health \ health_check \ app.py
import json
import sys
import my_elastic_search
def lambda_handler(event, context):
print(my_elastic_search.connect("myhost", "myuser", "mypass"))
# etc
. \ cluster_health \ health_check \ my_elastic_search.py
def connect(the_host, the_user, the_pass):
return "You are connected!"