Ошибка ModuleNotFoundError при мокинге с использованием pytest
Я использую pytest для написания модульных тестов в моем проекте django.
Но когда я хочу подружить метод в следующем коде:
@patch('smspanel.services.sms_panel_info_service.get_buinessman_sms_panel')
def test_send_plain_sms_success(mocker, businessman_with_customer_tuple):
mocker.return_value = SMSPanelInfo()
customer_ids = list(map(lambda e: e.id, businessman_with_customer_tuple[1]))
businessman = businessman_with_customer_tuple[0]
message = 'message'
result = services.send_plain_sms(user=businessman, customer_ids=customer_ids, message=message)
smsq = SMSMessage.objects.filter(
businessman=businessman,
message_type=SMSMessage.TYPE_PLAIN,
status=SMSMessage.STATUS_PENDING,
message=message)
assert smsq.exists()
sms = smsq.first()
receivers_count = SMSMessageReceivers.objects.filter(sms_message=sms, customer__id__in=customer_ids).count()
assert receivers_count == len(customer_ids)
Я получаю следующую ошибку:
thing = <module 'smspanel.services' from 'C:\\Users\\Pouya\\Desktop\\programs\\python\\marketpine-backend\\smspanel\\services.py'>
comp = 'sms_panel_info_service'
import_path = 'smspanel.services.sms_panel_info_service'
def _dot_lookup(thing, comp, import_path):
try:
return getattr(thing, comp)
except AttributeError:
> __import__(import_path)
E ModuleNotFoundError: No module named 'smspanel.services.sms_panel_info_service'; 'smspanel.services' is not a package
c:\users\pouya\anaconda3\lib\unittest\mock.py:1085: ModuleNotFoundError
Мой тестовый файл находится в smspanel/tests/test_services.py.