我可以模拟在Python测试中另一个函数调用中调用的函数返回吗?

问题描述

是否有一种方法可以模拟在另一个函数调用中调用的函数返回?例如:

def bar():
    return "baz"

def foo():
    return bar()

class Tests(unittest.TestCase):
    def test_code(self):
        # hijack bar() here to return "bat" instead
        assert(foo() == "bat")

我尝试使用@mock.patch,但是发现它只允许我模拟正在调用的函数,而不能模拟由于调用其他函数而被调用的函数。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)