Adam Haney

I'm an entrepreneur and hacker living in #cha. Working on a few different projects. You can find me on github, twitter and angel list.

Sitemap •  RSS Feed

Django Test Addons You Should Be Using

Nov. 2, 2013

I recently inherited a legacy Django application that had bugs and almost no tests. In an effort to make the project more maintainable I set out to cover the code in tests. I've spent the last few weeks scouring the internet searching for things to make testing easier and I've come up with a list of packages that you should be using to test your Django projects. For more information about helpful django apps that aren't related to testing checkout

Django Dynamic Fixtures

Creating objects manually in your setup methods can be extremely tedious (and isn't very DRY), but in my experience using test fixtures leads to brittle tests that break when you add or remove fields from your models. Django dynamic fixtures introspects your models and generates valid models for you to test about, you can specify the values of fields that are important for your tests, the rest will be filled with valid data. You can find the project at Other projects worth looking into that solve this project are Factory Boy ( and Model Mommy (


We've been focusing heavily on isolating our unit tests to only test code within our control (we use integration tests to test the way that models work together). In order to patch code that depends on outside libraries or resources we've been using the Mock package. Mocks allow us to make assertions about the number of times that a method is called, and the arguments it was called with. They also allow us to stub the response coming back from a third party library so we can verify that our logic works in the way we expect. For more information about the differences between unit and integration tests check out this conversation on Stack Overflow and for more information about the Mock library you can find its documentation at

Django Nose

Nose has tons of extensions that make testing with Django easier. Nose has options for caputuring log output and std out and displaying it only on test failure. It also has integrations with profiling and code coverage tools that make getting stats on your test suite and code much easier. Last but not least we've been using the attrs features in nose to tag tests by their type and optionally run our unit tests, integration tests and selenium tests separately. You can find more information about this feature at find more information about nose at


Django Nose also gives you the option to drop into pdb (the python debugger) when a test throws an exception or fails. the ipdbplugin package allows you to drop into ipdb which gives you tab completion and many of the other helpful features of ipython in your debugger. We've been writting and debugging a ton of code and every little bit of time saved helps. You can find the ipdb plugin at

Next entry

Previous entry:

comments powered by Disqus