def f1():
return 10, True
def f2():
num, stat = f1()
return 2*num, stat
如何使用 python 的模拟库来修补f1()
并返回自定义结果以便我可以测试f2()
?
编辑: 我的测试有问题吗?这似乎不起作用,所有测试都因 AssertionError 而失败
from foo.bar import f2
from mock import patch
class MyTest(TestCase):
def test_f2_1(self):
with patch('project.module.f1') as some_func:
some_func.return_value = (20, False)
num, stat = f2()
self.assertEqual((num, stat), (40, False))
@patch('project.module.f1')
def test_f2_2(self, some_func):
some_func.return_value = (20, False)
num, stat = f2()
self.assertEqual((num, stat), (40, False))