Speedily Practical Large-Scale Tests with Erik Rose from Votizen¶
PyCon 2012 presentation page: https://us.pycon.org/2012/schedule/presentation/473/
iStat menus for the Mac so you know your baseline memory usage, disk activity, etc.
Conquest of Speed parts:
- Per-class fixture loading
- Fixture bundling
- Startup Speedups
Got tests form 302 seconds down to 62 seconds.
- Finding and picking tests
- dealing with errors
Die, setUp(), die¶
More explicit test setup. Can be more efficient because you’re not setting up stuff you don’t need.
Die, fixtures, die¶
“model makers” – d = document(title=’test’)
Shared setup makes tests...
- Coupled to each other
- Hard to understand
- Kick puppies
Local setup gives you...
- Puppy kisses
Imperative vs. declarative
The Mock Library:
from mock import patch with patch.object(APIVoterManager, '_raw_voters') as voters: ....
The Fudge Library:
@fudge.patch('sphinxapi.SphinxClient') def test_single_filter(sphinx_client): .... (sphinx_client.expects_call().returns_fake() .is_a_stub() .expects('SetFilter').with_args('a', , False) .expects('SetFilter').... ....
Horrible dots - They don’t tell you anything
Hate tracebacks - too much noise
Erik Rose put together an alternative nose test runner called nose-progressive:
% nosetests --with-progressive
- displays a progress bar instead of dots so you know how long tests might take
- much abbreviated tracebacks
- editor shortcuts with the + syntax for line numbers that you can copy and paste to edit the file
How to install testing goodness:
pip install nose-progressive pip install django-nose
zope.testing package is pretty well-decoupled from the rest of Zope and easy to use with non-zope stuff. Also Twisted’s Trial test runner - someone noted that it’s nice but it doesn’t work with Django because Django is broken and wanted to sprint on it.
Someone mentioned that it’s nice to set up editor keybindings that run the tests for just the file you’re editing. Another way is to have something like autonose that automatically runs your tests for you.
MySQL sucks at everything; wants to switch to Postgres at Votizen.