[TIP] Bug with nosetests? Adding a new case with autospec=True will take 15 seconds

Dan Wandschneider daniel.wandschneider at schrodinger.com
Thu Mar 7 11:52:18 PST 2013


I have some guesses about this, which I elaborated on in:
http://stackoverflow.com/a/15280350/1309332

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:
1. Don't autospec.  Do you need it?
2. Only autospec some important method within the complex object that you
are replacing
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.

Good luck!
-Dan W.



On Wed, Mar 6, 2013 at 12:00 PM,
<testing-in-python-request at lists.idyll.org>wrote:

> Send testing-in-python mailing list submissions to
>         testing-in-python at lists.idyll.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://lists.idyll.org/listinfo/testing-in-python
> or, via email, send a message with subject or body 'help' to
>         testing-in-python-request at lists.idyll.org
>
> You can reach the person managing the list at
>         testing-in-python-owner at lists.idyll.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of testing-in-python digest..."
>
> Today's Topics:
>
>    1. Bug with nosetests? Adding a new case with autospec=True will
>       take 15 seconds (John Wong)
>
>
> ---------- Forwarded message ----------
> From: John Wong <gokoproject at gmail.com>
> To: testing-in-python at lists.idyll.org
> Cc:
> Date: Tue, 5 Mar 2013 22:57:29 -0500
> Subject: [TIP] Bug with nosetests? Adding a new case with autospec=True
> will take 15 seconds
> HI,
>
> Thanks for all the help so far.
>
> Here is the repo:
> https://bitbucket.org/yeukhon/bitbucket-python-api/src/6e57e95d5d09/tests/small?at=default
>
> I have a base unit test class in base.py.  For test_bitbucket.py, I
> inherit from the base unit test class.
> I want to add new test cases and classes to test_bitbucket.py While doing
> so, I discovered performance issue.
>
> I ran `nosetests` inside tests/small and I am getting these mix results
>
>
> Ran 18 tests in 14.523s        - autospec=True and test_account_creation
> exists
>
> Ran 18 tests in 0.621s         - autospec=False and
> test_account_creation_exists
>
>
> Ran 17 tests in 1.081s         - autospec=True and test_account_creation
> is deleted
>
> Ran 17 tests in 0.090s         - autospec=False, and test_account_creation
> is deleted
>
>
> 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.
>
> Interestingly, if we run test_bitbucket.py individually.
>
> (bbpy)yeukhon at yeukhon-P5E-VM-DO:~/hg/bitbucket-python-api/tests/small$
> nosetests test_bitbucket.py
> ...
> ----------------------------------------------------------------------
> Ran 3 tests in 0.090s
>
> OK
>
>
> Pretty much the same with/without autospec on.
>
> Any idea? I don't know enough about nosetests internal.
>
> Thanks!
>
> John
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20130307/5892ddf4/attachment.htm>


More information about the testing-in-python mailing list