Python模拟可以';得不到正确的返回值

Python模拟可以';得不到正确的返回值,python,unit-testing,mocking,return-value,Python,Unit Testing,Mocking,Return Value,我有下面的函数,其中包含一个模块中的python对象,并具有方法形状 def foo(image): print image.shape 我想模拟对象图像及其返回值 image = Mock() image.shape.return_value = (0,0) foo(image) >>> <Mock name='mock.shape' id='4416382544'> image=Mock() image.shape.return_值=(0,0) 傅(

我有下面的函数,其中包含一个模块中的python对象,并具有方法形状

def foo(image):
    print image.shape
我想模拟对象图像及其返回值

image = Mock()
image.shape.return_value = (0,0)
foo(image)
>>> <Mock name='mock.shape' id='4416382544'>
image=Mock()
image.shape.return_值=(0,0)
傅(图片)
>>> 
调用foo(image),image.shape将返回。如何使其返回(0,0)?(我需要获取值来测试某些条件,如if image.shape=(0,0)。 我正努力让它工作

谢谢你的帮助

image.shape = (0, 0)

直接设置属性。
return\u value
与属性访问无关。

print
不是
return
。此外,形状不是作为函数访问的,它是一个属性。您应该可以只执行
image.shape=(0,0)
其中
image
Mock
实例。谢谢。即使我正在使用def foo(image):return image.shape?我不确定返回值是什么then@RomanzoCriminale:
return\u value
用于调用函数之类的函数。
image.shape.return\u value
将是尝试
image.shape()
而不是
image.shape
时得到的结果。