<div dir="ltr"><div>Sorry for spamming with mock questions the last few days :)</div><div>Just doing some massive testing for complicated code.</div><div><br></div><div>I know that when I patch a specific method: </div><div>

<font class="Apple-style-span" face="&#39;courier new&#39;, monospace">@patch(&quot;package.MyClassName.my_method&quot;, new = Mock(return_value=&quot;xyz&quot;))</font></div><div><br></div><div>Even new instances of MyClass will return &quot;xyz&quot; as expected.</div>

<div><br></div><div>However, when I try:</div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">@patch(&quot;package.MyClassName&quot;)</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">def test_something(self, my_mock):</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">    my_mock.my_method.return_value = &quot;xyz&quot;</font></div>

<div><br></div><div>When in code I run:</div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">MyClassName().my_method()</font></div><div><br></div><div>I get a new different Mock and not &quot;xyz&quot; as I would wish.</div>

<div><br></div><div>Now, it kinda makes sense to me, but I would like to know if there&#39;s a way around it.</div><div>Couldn&#39;t really achieve this by mocking __init__ (or maybe I did it wrong?)</div><div><br></div>
<div>
Thanks!</div><div>Yoni.</div><div><div><br></div></div></div>