Sometimes it's handy to be able to generate an in memory image in your tests. This is faster than using an image from the filesystem, but the biggest benefit for me is not needing to spend ages wondering where exactly in your project you should store your single test image.
It wasn't obvious to me how to do this, but here's a snippet for anyone who wants it. I've tested this using Pillow (I guess it would work with PIL) with both Python 2.7 and Python 3 (3.3).
In my WebTest Django form test, I'd use it something like this:
Our CTO Richard gave a talk at PyCon UK, asking if it is ever worth committing coding sins for the greater good. He talked about techniques which can make your code easier to use at the cost of being harder to maintain, and when the effort is worth the reward.