doctest – Testing through documentation
This page has a somewhat in-depth set of examples for writing unit tests in Python with doctest.
http://pymotw.com/2/doctest/#working-around-whitespace specifically shows how to get around some whitespace formatting gotchas.