我有一个返回多个值的 python 函数。我的功能:
def myExampleFunction(a,b)
# here is my code
return name, number1, number2
def FunctionIWantToTest(self):
# here is my code
myName, myNumber1, myNumber2 = self.myExampleFunction(a,b)
我想将我自己的值赋予 FunctionIWantToTest 的返回值。所以,我正在尝试使用 nosetest 测试第二个函数,但我不知道如何模拟 myExampleFunction 的返回。
我试过这个:
def test_mytest(self):
[...]
c.myExampleFunction = Mock()
c.myExampleFunction.side_effect = ["myName", 100, 200]
[...]
但它不起作用。当我启动 nosetests 时,我读到了这条消息:
ValueError: too many values to unpack
有什么想法吗?我使用 python 2.7.3
最佳答案
您需要设置模拟的return_value
,而不是side_effect
。
你可以在实例化它的时候这样做:
c.myExampleFunction = Mock(return_value=["myName", 100, 200])
关于python - 具有多个返回值的模拟 python 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35774094/