[英]Python mocking can't get right return_value
I have the following function with image a python object from a module and having the method shape. 我有以下功能,从模块中获取一个python对象的图像,并具有方法形状。
def foo(image):
print image.shape
I want to mock the object image and it's return value 我想模拟对象图像及其返回值
image = Mock()
image.shape.return_value = (0,0)
foo(image)
>>> <Mock name='mock.shape' id='4416382544'>
Calling foo(image), image.shape will return . 调用foo(image),image.shape将返回。 How can I make it return (0,0)?
如何使它返回(0,0)? (I need to get the value to test some condition like if image.shape = (0,0). I'm struggling to have it work.
(我需要获取该值来测试诸如image.shape =(0,0)之类的某些条件。我正在努力使其正常工作。
Thanks for your help 谢谢你的帮助
image.shape = (0, 0)
Set the attribute directly. 直接设置属性。
return_value
has nothing to do with attribute accesses. return_value
与属性访问无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.