В файле1.py:
Код: Выделить всё
def fn_under_test(X):
if X:
getter_fn = fn1()
else:
getter_fn = fn2()
get_all_customers(getter_fn=getter_fn()
def get_all_customers(getter_fn):
return getter_fn()
def fn1():
raise Exception("I will fail")
def fn2():
raise Exception("I will fail")
test.py
Код: Выделить всё
from django.test import TestCase
from file1 import getAllCustomers
class Tests(TestCase):
def test(self):
patch('file1.fn1',
auto_spec=True
return_value = ['1', '2', '3']
)
result = fn_under_test(X=True)
self.assertEqual(result, ['1', '2', '3']
Подробнее здесь: https://stackoverflow.com/questions/786 ... n-argument