Моя структура папок выглядит следующим образом:
|- src
|- __init__.py
|- funcA.py
|- util.py
|- tests
|- __init__.py
|- test_funcA.py
|- test_util.py
Моя цель - протестировать функцию в funcA.py
def f():
try:
helper()
except Exception as e:
raise Exception('error: fail to call helper')
Вспомогательная функция в util.py
def helper():
try:
#do something
except Exception as e:
raise Exception('error: fail to do something')
модульный тест, который я пишу для f (), не охватывает эти две строки except Exception as e:
raise Exception('error: fail to call helper')
Вот мой тестовый пример для f
def test__f():
with mock.patch('src.utils.helper', side_effect=Exception('fail to call helper')):
from src import funcA
with pytest.raises(Exception):
funcA.f()
Как написать модульный тест, чтобы охватить исключение повышения f? Спасибо