Read my book

I wrote books about Webpack and React. Check them out!

Saturday, February 20, 2010

Book Review - Python Testing: Beginner's Guide

Disclaimer: I received a review copy of this book from the publisher, Packt Publishing.

The description of the book states following:
  • Covers everything you need to test your code in Python
  • Easiest and enjoyable approach to learn Python testing
  • Write, execute, and understand the result of tests in the unit test framework
  • Packed with step-by-step examples and clear explanations
I know it's marketing text but the book does manage to live up to the promise to some extent. :) Even though I'm quite set on my testing habits, I did manage to pick a couple of tricks from the book. The book is extremely pragmatic, perhaps even too much so.


As the description page of the book states, it is expected that the reader has some experience in Python. In case you are new to Python and still wish to proceed with the book, I would recommend checking out Dive Into Python or some other book oriented for beginners. The book does contain helpful notes that explain some of the advanced and possibly confusing concepts. So bonus points for that! Still, a good knowledge of object oriented programming in Python is a must.

Though the book has been written more of a "learning by doing" approach in mind, it does contain helpful reference and quizzes that help you to recap the main points. The free chapter should give a better idea of the structure for those interested.

Thoughts on Chapters

At first it felt strange that the book began by explaining how to use doctests but now, on retrospect, it makes more sense. The point of the book was that doctests may act more as a separate specification document. Considering it's still up to the developer to use it such way, I believe there are better ways of handling that. One such way is ATDD. There's even a framework available for that. I really wish the book would have at least hinted about alternative approaches.

Sometimes the example cases used felt a bit overwhelming and perhaps caused the main message to be muted a bit. I think it might have been interesting to see a case in which an application is grown in more organic manner. Now the examples provided felt perhaps a bit too specified. I know this may be due to my personal preference of building applications but still. :)

I liked particularly the chapter about Twill. I am definitely going to use that tool in the future at some point. Also the last chapter containing information about continuous integration, version control hooks and code coverage was enlightening and will serve as a nice reference.

Areas to Improve

It probably would have made sense to include a brief history of software testing as an appendix at least. Sure this would have meant the book contains more theory (I know, it's supposed to be a pragmatic book!) but I would not have mind at all. This would have given more credible justification to testing and given some nice references for the reader to study further. As it is, I strongly recommend picking up some other book more focused on theory of testing to complement this one. That probably would be a good idea in any case.

I was also surprised that a proper taxonomy of existing tools and approaches was not provided with the book. Sure it would get old, eventually. Still having one would have helped the reader to gain more general view of approaches used. Of course a proper one may be found here but that's not the point.

The book also failed to explicitly mention about concepts such as refactoring or fuzz testing. Both of which are quite crucial at least in my view. I admit that it can be tough to cover it all in one book but still. Perhaps they are saving those for a sequel. :)

There were also quite a few errata (over ten) which I ended up filing. That's probably forgivable considering it's the first edition. Hopefully those will be fixed up for the second one.

Checking the Claims

It's probably a good time to check out the claims of the book now:

  • Covers everything you need to test your code in Python

It's a bit tough to determine what you are going to need to test properly so the claim is a little ambiguous this way. The book does contain at least the minimal information to get started, at least.

  • Easiest and enjoyable approach to learn Python testing

Again, it's a bit subjective. I suppose it might do the trick for some people. Especially if you are willing to invest the time in studying the provided examples thoroughly. Getting in to the "testing mindset" can be a little daunting at first but the book should provide initial idea why it's nice to test.

  • Write, execute, and understand the result of tests in the unit test framework

Definitely true. No questions about that.

  • Packed with step-by-step examples and clear explanations

Again, definitely true. The prose was clear and understandable.


Considering there are not too many books focused on testing particularly in Python, I believe it was a good go at it. There were some issues but if you are willing to overlook those, this might just be the book for you.

If you end up buying the book, it might be a good idea to pick a book or two to complement it. Perhaps something about testing patterns or agile methologies in general might be a good pick.

The book is available at Packt and Amazon, at least.