【发布时间】:2019-07-02 18:59:57
【问题描述】:
我需要修补从同一文件导入的函数,该文件包含我要测试的另一个函数,但它不起作用 =/。
# funcs.py
def func_one():
return 1
def func_two():
return func_one() + 2
from .funcs import func_two
class TestFunc(TestCase):
def test_func_two(self):
with patch('func_one', 0):
result = func_two()
result 应该是两个,但我的测试出错了:
TypeError: Need a valid target to patch. You supplied: 'func_one'
【问题讨论】:
-
你需要修补
.func_one的.funcs,而不是你当前的模块。
标签: python mocking patch python-unittest