我试图理解,当我可以直接替换我想要模拟的对象时,为什么我需要使用模拟
例如,在这个人为的例子中
class Child:
def get(self):
return {0 : "SomeDictResult"}
class Root:
def __init__(self):
self.child = Child()
def get_info(self):
return self.child.get()
def test_get_info(root : Root):
root.child.get = lambda : {1 : "SomeOtherResult"} # This is where a mock would be
print(root.get_info())
我用一个带有自定义输出的lambda函数替换get,而不是mock。如果可以替换get
函数,为什么需要模拟呢
目前没有回答
相关问题 更多 >
编程相关推荐