views:

487

answers:

3

As I'm developing unit tests for my django application I find myself running manage.py test over and over and over again. I'm using a MySQL backend and have many models in the project, so the ramp up time to create all of the test databases is about 30 seconds.

How can I use make each unit test faster by keeping the database tables created and just clearing them of all records in-between runs of the "manage.py test" command?

+3  A: 

I haven't tried it, but there was a recent check in that is supposed to help by allowing the tests to be run inside transactions that are then rolled back:

Documentation and developer commentary

+3  A: 

Note that you don't have to run the entire test suite every time. You can just run the test suite for a single app by running manage.py test appname (or for multiple apps at once with manage.py test app1 app2 ...).

My usual workflow is to just run the tests for the app I'm working on as I work, and the run the full suite before I commit my next set of changes.

jacobian
A: 

You can run your tests using the sqlite database backend. It's not appropriate for a full test run (since the db is different), but for sanity checks it saves a lot of time. See: http://mindlesstechnology.wordpress.com/2008/08/16/faster-django-unit-tests/

Seth