Reputation: 1349
I have the following function with image a python object from a module and having the method shape.
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 . How can I make it return (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.
Thanks for your help
Upvotes: 0
Views: 167
Reputation: 280311
image.shape = (0, 0)
Set the attribute directly. return_value
has nothing to do with attribute accesses.
Upvotes: 1