Closed GoogleCodeExporter closed 9 years ago
No, sorry. The return value is a single object. If you want multiple returned
mocks you will have to implement a side_effect that does this for you.
(Otherwise getting access back to the returned mocks to make assertions on them
would be difficult.)
Original comment by fuzzyman
on 28 Jun 2011 at 2:38
Thank you very much for you comment.
Using a side effect solves the usage of patch but I can not use the same
technique for patch.object.
I think that it is worth mentioning in TODO and limitation section and add the
patch on classes in Other examples section.
Cheers,
Adi
Original comment by adiroi...@gmail.com
on 28 Jun 2011 at 3:49
Why can't you use side_effect with patch.object? The side_effect should be
attached to the *mock* (either on creation or after). Whether it is done
through patch or patch.object is irrelevant.
Original comment by fuzzyman
on 28 Jun 2011 at 3:51
Thanks for your comment!
I am trying to use the attached code for creating different method instances
but I don't know how to get it right.
from mock import patch, Mock
class DemoClass(object):
def __init__(self):
pass
def something(self):
pass
if __name__ == "__main__":
def side_effect(*args, **kwargs):
return Mock()
with patch.object(DemoClass, 'something', side_effect=side_effect):
one = DemoClass()
two = DemoClass()
assert one is not two
assert one.something is not two.something
Original comment by adiroi...@gmail.com
on 28 Jun 2011 at 4:12
Attachments:
In that case you are *not* patching DemoClass itself, you are just patching the
'something' method on it. So calling DemoClass doesn't touch your mock at all.
Original comment by fuzzyman
on 28 Jun 2011 at 4:31
Original issue reported on code.google.com by
adiroi...@gmail.com
on 28 Jun 2011 at 2:36