Igor Sobreira

Improving performance of Django test suite

I'm working on a small django application these days which offers templates to override django-filebrowser's templates to remove the Grappelli dependency.

It's a small app, consisting 99% of templates. There are only 19 tests which take 35 seconds to execute! All of them performs at least one request using django test client, no selenium, no real HTTP requests, and still 35 seconds!

Tests speed very slow

After a run with cProfile I've noticed many calls to hash functions, specifically django.utils.crypto.pbkdf2() and it's helper _fast_hmac. Then I came up with this very complex patch to my settings:

+        'django.contrib.auth.hashers.UnsaltedMD5PasswordHasher',   
+    ),

Now the tests execute on 6 seconds!

Tests speed improved

You probably want a safer hash function for your user passwords in production, but there is no problem to use a simpler one for tests. This extensible way to deal with password hashers was introduced in Django 1.4, you can read more about it on the docs.

blog comments powered by Disqus