模拟从输入参数派生的函数的返回值



我想模拟从输入参数(a)派生的函数的返回值。
我的代码是这样的

def load_data(a, b, c):
data_source = a.get_function(b, c)
...
return r_1, r_2, r_3

这是我尝试过的,但没有成功。我找不到任何模拟此类型函数返回的源代码。

@classmethod
def setUpClass(cls):
cls.a = A.create()
cls.data_needed_return = read_file()
def test_function(self):
mocked = mock.Mock()
self.a.get_function.return_value = self.data_needed_return
import python_file
data_source = python_file.load_data(None, None, None)

有人能帮忙吗?

不确定我是否正确理解了您的问题和问题,但您是否正在寻找以下内容?


from unittest.mock import Mock
def load_data(a, b, c):
data_source = a.get_function(b, c)
return data_source
a = Mock()
a.get_function.return_value = "Some data"
x = load_data(a, 2, 3)
print(x)