[Answered ]-Django testing wastes too much time on test database creating

2👍

You can use django-nose and reuse the database like this:

REUSE_DB=1 ./manage.py test

Be careful that your tests do not leave any junk in the DB. Have a look at the documentation for more info.

0👍

At some point I ended up creating a transaction management middleware that would intercept transaction calls so that all tests were run in a transaction, and then the transaction was rolled back at the end.

Another alternative is to have a binary database dump that gets loaded at the beginning of each test, and then the database is dropped and recreated between tests. After creating a good database, use xtrabackup to create a dump of it. Then, in a per-test setup function, drop and create the database, then use xtrabackup to load the dump. Since it’s a binary dump it’ll load fairly quickly.

Leave a comment