Hi,<div>Sorry for the spam. Actually, I looked at it again. I feel like the way I was patching was fundamentally incorrect. </div><div><br><div>#bitbucket/apis.py</div><div>import requests</div><div><br></div><div>def foo(..):</div>
<div>    requests.get(...)</div><div><br></div><div>then in my test I should just patch.object(requests, &#39;get&#39;) and not patch(&#39;bitbucket.apis.requests&#39;, autospec=True)</div><div><br></div><div>I think that&#39;s one mistake I made, if I read the doc correctly. </div>
<div>Thanks.</div><div><br></div><div>John</div><div><div class="gmail_quote">On Sat, Mar 9, 2013 at 7:12 PM, John Wong <span dir="ltr">&lt;<a href="mailto:gokoproject@gmail.com" target="_blank">gokoproject@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">Thanks! Finally can get back to this.<div>Yes. I ahve to agree that I should just patch out certain things like requests.get, and requests.post only.<br>
<div><br></div><div><div class="im"><div>(bbpy)yeukhon@yeukhon-P5E-VM-DO:~/hg/bitbucket-python-api/tests/small$ nosetests test_bitbucket.py</div>
<div>...</div><div>----------------------------------------------------------------------</div></div><div>Ran 3 tests in 0.103s</div><div><br></div><div>OK</div><div><br></div><div><br></div><div>This is an individual test. It ran 3 tests. One of which is a new test class I tried to add (which just has one test case)</div>

<div><br></div><div>If I comment out the new test class in test_bitbucket.py, and ran the entire suite:</div><div><div>(bbpy)yeukhon@yeukhon-P5E-VM-DO:~/hg/bitbucket-python-api/tests/small$ nosetests</div><div>.................</div>

<div>----------------------------------------------------------------------</div><div>Ran 17 tests in 1.020s</div><div><br></div><div>OK</div></div><div><br></div><div>As you can see. For some strange reasons, a new test class would trigger a big jump!</div>

<div><br></div><div>I did a little debugging using nose&#39;s set_tace()</div><div><br></div><div>run &quot;nosetest&quot; with debug: <a href="http://pastebin.com/YK7yXrtG" target="_blank">http://pastebin.com/YK7yXrtG</a></div>
<div>run &quot;nsoetest test_bitbucket.py&quot; <a href="http://pastebin.com/WbfEYKnL" target="_blank">http://pastebin.com/WbfEYKnL</a></div>
<div><br></div><div>I can understand the one with all tests would do some discovery so the debug log looks longer. </div><span class="HOEnZb"><font color="#888888"><div><br></div><div>John</div></font></span><div><div class="h5">
<div><br><div class="gmail_quote">On Fri, Mar 8, 2013 at 8:40 AM, Michael Foord <span dir="ltr">&lt;<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br>
On 7 Mar 2013, at 19:52, Dan Wandschneider &lt;<a href="mailto:daniel.wandschneider@schrodinger.com" target="_blank">daniel.wandschneider@schrodinger.com</a>&gt; wrote:<br>
<br>
&gt; I have some guesses about this, which I elaborated on in:<br>
&gt; <a href="http://stackoverflow.com/a/15280350/1309332" target="_blank">http://stackoverflow.com/a/15280350/1309332</a><br>
&gt;<br>
&gt; But basically, it looks like the recursive calls to create_autospec() are slowing down on your mocked object (whatever it is).  ID recommend one of three approaches:<br>
&gt; 1. Don&#39;t autospec.  Do you need it?<br>
&gt; 2. Only autospec some important method within the complex object that you are replacing<br>
&gt; 3. use instance=True to limit the depth of recursion of calls to create_autospec().  This may change behavior that you are depending upon, however.  Be careful, since you are essentially lying to mock.patch if you do this.<br>


&gt;<br>
<br>
<br>
</div>The issue is that adding one test (class/module ?)  slows the test run down by 13 seconds or so. What is needed is running that test on its own (with create_autospec on) to see if it actually takes that long or whether there is some additional mysterious source of slowdown (which the OP seems to suspect).<br>


<br>
Adding &quot;instance=True&quot; to *the patch call* is probably a bad idea.<br>
<br>
It is entirely *possible* that autospec is really, really slow in some cases - but to be that much slower is very odd.<br>
<br>
Michael<br>
<div><div><br>
&gt; Good luck!<br>
&gt; -Dan W.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Mar 6, 2013 at 12:00 PM, &lt;<a href="mailto:testing-in-python-request@lists.idyll.org" target="_blank">testing-in-python-request@lists.idyll.org</a>&gt; wrote:<br>
&gt; Send testing-in-python mailing list submissions to<br>
&gt;         <a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
&gt;<br>
&gt; To subscribe or unsubscribe via the World Wide Web, visit<br>
&gt;         <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
&gt; or, via email, send a message with subject or body &#39;help&#39; to<br>
&gt;         <a href="mailto:testing-in-python-request@lists.idyll.org" target="_blank">testing-in-python-request@lists.idyll.org</a><br>
&gt;<br>
&gt; You can reach the person managing the list at<br>
&gt;         <a href="mailto:testing-in-python-owner@lists.idyll.org" target="_blank">testing-in-python-owner@lists.idyll.org</a><br>
&gt;<br>
&gt; When replying, please edit your Subject line so it is more specific<br>
&gt; than &quot;Re: Contents of testing-in-python digest...&quot;<br>
&gt;<br>
&gt; Today&#39;s Topics:<br>
&gt;<br>
&gt;    1. Bug with nosetests? Adding a new case with autospec=True will<br>
&gt;       take 15 seconds (John Wong)<br>
&gt;<br>
&gt;<br>
&gt; ---------- Forwarded message ----------<br>
&gt; From: John Wong &lt;<a href="mailto:gokoproject@gmail.com" target="_blank">gokoproject@gmail.com</a>&gt;<br>
&gt; To: <a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
&gt; Cc:<br>
&gt; Date: Tue, 5 Mar 2013 22:57:29 -0500<br>
&gt; Subject: [TIP] Bug with nosetests? Adding a new case with autospec=True will take 15 seconds<br>
&gt; HI,<br>
&gt;<br>
&gt; Thanks for all the help so far.<br>
&gt;<br>
&gt; Here is the repo: <a href="https://bitbucket.org/yeukhon/bitbucket-python-api/src/6e57e95d5d09/tests/small?at=default" target="_blank">https://bitbucket.org/yeukhon/bitbucket-python-api/src/6e57e95d5d09/tests/small?at=default</a><br>


&gt;<br>
&gt; I have a base unit test class in base.py.  For test_bitbucket.py, I inherit from the base unit test class.<br>
&gt; I want to add new test cases and classes to test_bitbucket.py While doing so, I discovered performance issue.<br>
&gt;<br>
&gt; I ran `nosetests` inside tests/small and I am getting these mix results<br>
&gt;<br>
&gt;<br>
&gt; Ran 18 tests in 14.523s        - autospec=True and test_account_creation exists<br>
&gt;<br>
&gt; Ran 18 tests in 0.621s         - autospec=False and test_account_creation_exists<br>
&gt;<br>
&gt;<br>
&gt; Ran 17 tests in 1.081s         - autospec=True and test_account_creation is deleted<br>
&gt;<br>
&gt; Ran 17 tests in 0.090s         - autospec=False, and test_account_creation is deleted<br>
&gt;<br>
&gt;<br>
&gt; I understand requests is a big library, but the performance hit is crazy, going from 1.1s to 14.5s with and without the new test class, respectively.<br>
&gt;<br>
&gt; Interestingly, if we run test_bitbucket.py individually.<br>
&gt;<br>
&gt; (bbpy)yeukhon@yeukhon-P5E-VM-DO:~/hg/bitbucket-python-api/tests/small$ nosetests test_bitbucket.py<br>
&gt; ...<br>
&gt; ----------------------------------------------------------------------<br>
&gt; Ran 3 tests in 0.090s<br>
&gt;<br>
&gt; OK<br>
&gt;<br>
&gt;<br>
&gt; Pretty much the same with/without autospec on.<br>
&gt;<br>
&gt; Any idea? I don&#39;t know enough about nosetests internal.<br>
&gt;<br>
&gt; Thanks!<br>
&gt;<br>
&gt; John<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; testing-in-python mailing list<br>
&gt; <a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
&gt; <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; testing-in-python mailing list<br>
&gt; <a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
&gt; <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br>
<br>
</div></div>--<br>
<a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br>
<br>
<br>
May you do good and not evil<br>
May you find forgiveness for yourself and forgive others<br>
May you share freely, never taking more than you give.<br>
-- the sqlite blessing<br>
<a href="http://www.sqlite.org/different.html" target="_blank">http://www.sqlite.org/different.html</a><br>
<div><div><br>
<br>
<br>
<br>
<br>
<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>
</div></div></blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div></div>