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, 'get') and not patch('bitbucket.apis.requests', autospec=True)</div><div><br></div><div>I think that'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"><<a href="mailto:gokoproject@gmail.com" target="_blank">gokoproject@gmail.com</a>></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's set_tace()</div><div><br></div><div>run "nosetest" with debug: <a href="http://pastebin.com/YK7yXrtG" target="_blank">http://pastebin.com/YK7yXrtG</a></div>
<div>run "nsoetest test_bitbucket.py" <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"><<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a>></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 <<a href="mailto:daniel.wandschneider@schrodinger.com" target="_blank">daniel.wandschneider@schrodinger.com</a>> wrote:<br>
<br>
> I have some guesses about this, which I elaborated on in:<br>
> <a href="http://stackoverflow.com/a/15280350/1309332" target="_blank">http://stackoverflow.com/a/15280350/1309332</a><br>
><br>
> 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>
> 1. Don't autospec. Do you need it?<br>
> 2. Only autospec some important method within the complex object that you are replacing<br>
> 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>
><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 "instance=True" 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>
> Good luck!<br>
> -Dan W.<br>
><br>
><br>
><br>
> On Wed, Mar 6, 2013 at 12:00 PM, <<a href="mailto:testing-in-python-request@lists.idyll.org" target="_blank">testing-in-python-request@lists.idyll.org</a>> wrote:<br>
> Send testing-in-python mailing list submissions to<br>
> <a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
><br>
> To subscribe or unsubscribe via the World Wide Web, visit<br>
> <a href="http://lists.idyll.org/listinfo/testing-in-python" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
> or, via email, send a message with subject or body 'help' to<br>
> <a href="mailto:testing-in-python-request@lists.idyll.org" target="_blank">testing-in-python-request@lists.idyll.org</a><br>
><br>
> You can reach the person managing the list at<br>
> <a href="mailto:testing-in-python-owner@lists.idyll.org" target="_blank">testing-in-python-owner@lists.idyll.org</a><br>
><br>
> When replying, please edit your Subject line so it is more specific<br>
> than "Re: Contents of testing-in-python digest..."<br>
><br>
> Today's Topics:<br>
><br>
> 1. Bug with nosetests? Adding a new case with autospec=True will<br>
> take 15 seconds (John Wong)<br>
><br>
><br>
> ---------- Forwarded message ----------<br>
> From: John Wong <<a href="mailto:gokoproject@gmail.com" target="_blank">gokoproject@gmail.com</a>><br>
> To: <a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
> Cc:<br>
> Date: Tue, 5 Mar 2013 22:57:29 -0500<br>
> Subject: [TIP] Bug with nosetests? Adding a new case with autospec=True will take 15 seconds<br>
> HI,<br>
><br>
> Thanks for all the help so far.<br>
><br>
> 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>
><br>
> I have a base unit test class in base.py. For test_bitbucket.py, I inherit from the base unit test class.<br>
> I want to add new test cases and classes to test_bitbucket.py While doing so, I discovered performance issue.<br>
><br>
> I ran `nosetests` inside tests/small and I am getting these mix results<br>
><br>
><br>
> Ran 18 tests in 14.523s - autospec=True and test_account_creation exists<br>
><br>
> Ran 18 tests in 0.621s - autospec=False and test_account_creation_exists<br>
><br>
><br>
> Ran 17 tests in 1.081s - autospec=True and test_account_creation is deleted<br>
><br>
> Ran 17 tests in 0.090s - autospec=False, and test_account_creation is deleted<br>
><br>
><br>
> 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>
><br>
> Interestingly, if we run test_bitbucket.py individually.<br>
><br>
> (bbpy)yeukhon@yeukhon-P5E-VM-DO:~/hg/bitbucket-python-api/tests/small$ nosetests test_bitbucket.py<br>
> ...<br>
> ----------------------------------------------------------------------<br>
> Ran 3 tests in 0.090s<br>
><br>
> OK<br>
><br>
><br>
> Pretty much the same with/without autospec on.<br>
><br>
> Any idea? I don't know enough about nosetests internal.<br>
><br>
> Thanks!<br>
><br>
> John<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>
><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>
<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>