[TIP] [Python 2] Objects' mocked magic method returns another mock
Matthew J. Morrison
mattjmorrison at mattjmorrison.com
Sat Oct 1 09:10:26 PDT 2011
You'll need to make sure that the __int__ method returns an int.
after your PATCH.start() try adding
T1.__int__.return_value = 1
On Sat, Oct 1, 2011 at 5:12 AM, Alexandre Gravier <
alexandre.gravier at gmail.com> wrote:
> Hi testers-in-python,
> I am stuck on the following:
> from mock import patch
> class TestObject(object):
> def __int__(self):
> return 42
> PATCH = patch.object(TestObject, "__int__")
> T1 = TestObject()
> print "int(T1) with patched class:", int(T1)
> Output: [...]
> TypeError: __int__ returned non-int (type Mock)
> Am I understanding mock.patch.object incorrectly? I need to temporarily
> mock the __int__ macig method, so the patch should be stop()able.
> The platform is Python 2.7.2, linux, 32 bit, mock 0.7.2, virtualenv, yadda
> Does anyone have some idea to help me understand what I'm doing wrong?
> Thanks :)
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python