<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    On 02/10/2011 05:44, Alexandre Gravier wrote:
    <blockquote
cite="mid:CAOZahavrSChs_EDyytDRkDRSVov0ifp2tvgqGbSwzibU661O3A@mail.gmail.com"
      type="cite">
      <div>Thank you, you are right, this solves my problem.&nbsp;</div>
      <div><br>
      </div>
      <div>I assumed that the MagicMock default return values applied (<a
          moz-do-not-send="true"
          href="http://www.voidspace.org.uk/python/mock/magicmock.html#magic-mock">http://www.voidspace.org.uk/python/mock/magicmock.html#magic-mock</a>)
        without actually trying manually.</div>
      <br>
    </blockquote>
    <br>
    You're not actually using a MagicMock here, you're patching out the
    __int__ method on a class with another Mock. In 0.8 patch will use a
    MagicMock by default - but that still won't help your case. It isn't
    the magic method of the mock that is being called - the mock is
    called directly when TestObject.__int__ is called. <br>
    <br>
    As Matthew said, the fix is to ensure your mock returns an integer.
    You can do this in the patch call:<br>
    <br>
    &nbsp;&nbsp;&nbsp; PATCH = patch.object(TestObject, "__int__", return_value=3)<br>
    <br>
    All the best,<br>
    <br>
    Michael Foord<br>
    <br>
    <blockquote
cite="mid:CAOZahavrSChs_EDyytDRkDRSVov0ifp2tvgqGbSwzibU661O3A@mail.gmail.com"
      type="cite">Cheers
      <div>Alexandre<br>
        <br>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">
          Date: Sat, 1 Oct 2011 11:10:26 -0500<br>
          From: "Matthew J. Morrison" &lt;<a moz-do-not-send="true"
            href="javascript:;" onclick="_e(event, 'cvml',
            'mattjmorrison@mattjmorrison.com')">mattjmorrison@mattjmorrison.com</a>&gt;<br>
          Subject: Re: [TIP] [Python 2] Objects' mocked magic method
          returns<br>
          &nbsp; &nbsp; &nbsp; &nbsp;another mock<br>
          To: "<a moz-do-not-send="true" href="javascript:;"
            onclick="_e(event, 'cvml',
            'testing-in-python@lists.idyll.org')">testing-in-python@lists.idyll.org</a>"<br>
          &nbsp; &nbsp; &nbsp; &nbsp;&lt;<a moz-do-not-send="true" href="javascript:;"
            onclick="_e(event, 'cvml',
            'testing-in-python@lists.idyll.org')">testing-in-python@lists.idyll.org</a>&gt;<br>
          Message-ID:<br>
          &nbsp; &nbsp; &nbsp; &nbsp;&lt;<a moz-do-not-send="true" href="javascript:;"
            onclick="_e(event, 'cvml',
            'CAKUA1R7bdDkPWoNYjcRjTMRp99JRpU5KBk2Tq8Cg6iZ-D+5sdQ@mail.gmail.com')">CAKUA1R7bdDkPWoNYjcRjTMRp99JRpU5KBk2Tq8Cg6iZ-D+5sdQ@mail.gmail.com</a>&gt;<br>
          Content-Type: text/plain; charset="iso-8859-1"<br>
          <br>
          You'll need to make sure that the __int__ method returns an
          int.<br>
          <br>
          after your PATCH.start() try adding<br>
          <br>
          T1.__int__.return_value = 1<br>
          <br>
          On Sat, Oct 1, 2011 at 5:12 AM, Alexandre Gravier &lt;<br>
          <a moz-do-not-send="true" href="javascript:;"
            onclick="_e(event, 'cvml', 'alexandre.gravier@gmail.com')">alexandre.gravier@gmail.com</a>&gt;
          wrote:<br>
          <br>
          &gt; Hi testers-in-python,<br>
          &gt;<br>
          &gt; I am stuck on the following:<br>
          &gt;<br>
          &gt; from mock import patch<br>
          &gt;<br>
          &gt; class TestObject(object):<br>
          &gt; &nbsp; &nbsp; def __int__(self):<br>
          &gt; &nbsp; &nbsp; &nbsp; &nbsp; return 42<br>
          &gt;<br>
          &gt; PATCH = patch.object(TestObject, "__int__")<br>
          &gt; T1 = TestObject()<br>
          &gt; PATCH.start()<br>
          &gt; print "int(T1) with patched class:", int(T1)<br>
          &gt;<br>
          &gt; Output: [...]<br>
          &gt; TypeError: __int__ returned non-int (type Mock)<br>
          &gt;<br>
          &gt; Am I understanding mock.patch.object incorrectly? I need
          to temporarily<br>
          &gt; mock the __int__ macig method, so the patch should be
          stop()able.<br>
          &gt; The platform is Python 2.7.2, linux, 32 bit, mock 0.7.2,
          virtualenv, yadda<br>
          &gt; yadda<br>
          &gt;<br>
          &gt; Does anyone have some idea to help me understand what I'm
          doing wrong?<br>
          &gt;<br>
          &gt; Thanks :)<br>
          &gt; Alexandre<br>
          &gt;<br>
          &gt; _______________________________________________<br>
          &gt; testing-in-python mailing list<br>
          <br>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
testing-in-python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
<a class="moz-txt-link-freetext" href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a>
</pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.voidspace.org.uk/">http://www.voidspace.org.uk/</a>

May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing <a class="moz-txt-link-freetext" href="http://www.sqlite.org/different.html">http://www.sqlite.org/different.html</a>
</pre>
  </body>
</html>