Python,Mockito,Mocking另一个模块';s进口
假设我有module1.pyPython,Mockito,Mocking另一个模块';s进口,python,mockito,Python,Mockito,假设我有module1.py from my_library import useful_function def do_something(x): return useful_function(x) 我正在测试module2.py from module1 import do_something def do_something_else(x): return do_something(x+1) 有用的_函数执行数据库调用,因此我想将其去掉以返回一个常量值 我如何使用m
from my_library import useful_function
def do_something(x):
return useful_function(x)
我正在测试module2.py
from module1 import do_something
def do_something_else(x):
return do_something(x+1)
有用的_函数执行数据库调用,因此我想将其去掉以返回一个常量值
我如何使用mockito删除有用的函数?我已尝试导入我的_库,并使用
when( my_library ).useful_function('abc').thenReturn(...)
但这是行不通的。如果我暂停Eclipse并将鼠标悬停在do_something()中有用的_函数行上,那么有用的_函数()似乎没有被截断
import module1
module1.useful_function = Mock(...)
return do_something(x+1)