Django 1.1 Testing and Debugging

I just finished reading the copy of Django 1.1 Testing and Debugging by Karen M. Tracey provided to us for review by Packt Publishing. For those of you who don’t know, Karen is a core developer of Django and her knowledge and experience in the framework shines through in this book.

This is a great book for people who want to transition from being a hobbyist tinkering on Django sites to professional developers. It will be a lot to digest for a newcomer to Django and might not contain much new information if you’ve been working with Django for a while (and writing tests for your code). The book covers:

  • doctests vs. unit tests
  • integrating external tools like Nose, Coverage, and Twill
  • debugging with logging, Django Debug Toolbar, and pdb
  • how to get help from the Django community and file bugs
  • troubleshooting Apache/mod_wsgi deployments

Even though I’ve been working with Django for a few years now, I still picked up some great tips and got a few nice refreshers after reading the book. In Chapter 5, Karen describes how to use Twill instead of the built-in test client. As somebody who has written tests for multi-page form wizards with an automatically generated hash, I wish I had thought of this technique at the time. By using Twill, you can ignore auto-filled form fields and just test the functionality you care about.

Another great thing about this book are the non-trivial code samples included. I love reading other people’s code. You can learn a lot by seeing how other people solve problems and their general coding style. One item that struck me was the use of reverse(admin:[url_name]) in some of the examples. I had missed the addition of URL namespaces in Django 1.1 and will definitely be integrating them into my code in the future.

If you don’t have much experience with testing or real debugging (not sprinkling print statements) and are looking to make the leap to professional development with Django, I strongly recommend grabbing a copy of this book. You’ll learn a lot and it will make a great reference manual for your bookshelf.