<div dir="ltr">Mahdi,<div><br></div><div>Hmmm there&#39;s something fishy here... I trimmed down your example as best as I could and I could not reproduce the problem you&#39;re having. Please take a look: <a href="https://gist.github.com/nicoddemus/d100e3659db7fdddf691">https://gist.github.com/nicoddemus/d100e3659db7fdddf691</a></div>

<div><br></div><div>As the py.test output shows, mocking the twitter module works. The approach I suggested should also have worked (see Gist comments). Which version of the mock module are you using?</div><div><br></div>

<div>Cheers,</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 7, 2014 at 7:02 PM, Mahdi Yusuf <span dir="ltr">&lt;<a href="mailto:yusuf.mahdi@gmail.com" target="_blank">yusuf.mahdi@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Bruno, <div><br></div><div>I would like to avoid changing code, especially without a reason. I have already tried this route and doesn&#39;t work (tried it again now, for human error). :) mechanize_url still runs as implemented. </div>



<div><br></div><div>Thanks for your response. </div><div><br></div><div>--</div><div>Mahdi Yusuf</div></div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">On Fri, Feb 7, 2014 at 3:43 PM, Bruno Oliveira <span dir="ltr">&lt;<a href="mailto:nicoddemus@gmail.com" target="_blank">nicoddemus@gmail.com</a>&gt;</span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Mahdi,<div><br></div><div>If you can change your code, try to import the module instead of the function in <font face="courier new, monospace">twitter_profile.py</font>:</div>



<div><br></div><div><span style="line-height:16.799999237060547px;font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">      from</span><span style="line-height:16.799999237060547px;font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace"> </span><span style="color:rgb(85,85,85);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:16.799999237060547px;white-space:pre-wrap">miners import task_utils</span><br>





</div><div><span style="line-height:16.799999237060547px;color:rgb(51,51,51);font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace"><br>

</span></div><div>And use it as such in the code.<br></div><div><br></div><div><pre style="line-height:16.799999237060547px;width:744px;font-size:12px;margin-bottom:0px;margin-top:0px;padding:0px"><div style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">

<span style="font-weight:bold">      try</span><span>:</span></div><div style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">



          <span style="color:rgb(51,51,51)">html</span> <span style="font-weight:bold">=</span> <span style="color:rgb(85,85,85)">task_utils.</span><span style="color:rgb(51,51,51)">mechanize_url</span><span>(</span><span style="color:rgb(51,51,51)">url</span><span>)</span></div>





<div style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">      <span style="font-weight:bold">except</span><span>:</span></div><div style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">





<span>          ...</span></div><div style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace"><span><br></span></div><div>

<span style="font-family:arial;color:rgb(34,34,34);font-size:small;line-height:normal;white-space:normal">Then mocking using </span><span style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;color:rgb(51,51,51);white-space:pre-wrap">mock</span><span style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;color:rgb(34,34,34);white-space:pre-wrap;font-weight:bold">.</span><span style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;color:rgb(51,51,51);white-space:pre-wrap">patch</span><span style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;color:rgb(34,34,34);white-space:pre-wrap">(</span><span style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;color:rgb(221,17,68);white-space:pre-wrap">&#39;miners.tasks_utils.mechanize_url&#39;</span><span style="color:rgb(34,34,34);white-space:pre-wrap"><font face="Consolas, Liberation Mono, Courier, monospace">) </font><font face="arial, helvetica, sans-serif">should work.</font></span><font face="Consolas, Liberation Mono, Courier, monospace"><br>





</font></div><div style="font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace"><span style="color:rgb(34,34,34);white-space:pre-wrap"><br></span></div><div>

<span style="color:rgb(34,34,34);white-space:pre-wrap"><font face="arial, helvetica, sans-serif">Hope this helps,</font></span></div></pre></div></div><div><div><div class="gmail_extra"><br><br>

<div class="gmail_quote">On Fri, Feb 7, 2014 at 2:18 PM, Mahdi Yusuf <span dir="ltr">&lt;<a href="mailto:yusuf.mahdi@gmail.com" target="_blank">yusuf.mahdi@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">David, <div><br></div><div>Thanks for your response. I tried that when I was exhausting all my options. That also doesn&#39;t work. </div>





<div><br></div><div>--</div><div>Mahdi Yusuf</div></div><div class="gmail_extra"><div><div>

<br><br><div class="gmail_quote">On Fri, Feb 7, 2014 at 11:07 AM, David Stanek <span dir="ltr">&lt;<a href="mailto:dstanek@dstanek.com" target="_blank">dstanek@dstanek.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">







<div dir="ltr">Instead of <span style="line-height:16.799999237060547px;color:rgb(51,51,51);font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">mock</span><span style="line-height:16.799999237060547px;font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-weight:bold">.</span><span style="line-height:16.799999237060547px;color:rgb(51,51,51);font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">patch</span><span style="line-height:16.799999237060547px;font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">(</span><span style="color:rgb(221,17,68);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:16.799999237060547px;white-space:pre-wrap">&#39;miners.tasks_utils.mechanize_url&#39;</span><span style="line-height:16.799999237060547px;font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">)</span> you should try <span style="line-height:16.799999237060547px;color:rgb(51,51,51);font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">mock</span><span style="line-height:16.799999237060547px;font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-weight:bold">.</span><span style="line-height:16.799999237060547px;color:rgb(51,51,51);font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">patch</span><span style="line-height:16.799999237060547px;font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">(</span><span style="color:rgb(221,17,68);font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;font-size:12px;line-height:16.799999237060547px;white-space:pre-wrap">&#39;twitter_profile.mechanize_url&#39;</span><span style="line-height:16.799999237060547px;font-size:12px;white-space:pre-wrap;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace">)</span>. <div>








<br></div><div>Once your twitter_profile module is imported it will have a reference to mechanize_url.  When you patch miners.tasks_utils you are not changing this reference.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">







<div><div>
On Fri, Feb 7, 2014 at 10:42 AM, Mahdi Yusuf <span dir="ltr">&lt;<a href="mailto:yusuf.mahdi@gmail.com" target="_blank">yusuf.mahdi@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">







<div><div>
<div dir="ltr">I am at my wits end pretty much. I am not sure what is happening here. <div><br></div><div>I am unable to mock an import function. My code is <a href="https://gist.github.com/myusuf3/685083e70bf3f93fd43c" target="_blank">here</a>. After some reading I know you patch where the function is used not where its defined.</div>










<div><br></div><div>I have also tried everything else but the mechanize_url is till running as implemented in code not mocked in test.</div><div><br></div><div>Thoughts? </div><span><font color="#888888"><div>
<br></div><div>-- <br><div>Mahdi Yusuf</div>


</div></font></span></div>
<br></div></div>_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br>David<br>blog: <a href="http://www.traceback.org" target="_blank">http://www.traceback.org</a><br>twitter: <a href="http://twitter.com/dstanek" target="_blank">http://twitter.com/dstanek</a><div>








www: <a href="http://dstanek.com" target="_blank">http://dstanek.com</a></div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span><font color="#888888">-- <br><div>Mahdi Yusuf</div>
</font></span></div>
<br>_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div>Mahdi Yusuf</div>
</font></span></div>
</blockquote></div><br></div>