[Zope-dev] Re: Unit Test Failures

Jim Fulton jim at zope.com
Mon Dec 19 10:38:21 EST 2005


Tres Seaver wrote:
> I see a couple of problem points:  the
> biggest is the use in the output of 'checkSiteManager.html' of a repr'ed
> dict, which might render differently between different machines (or even
> the same machine across Python versions).  This is a classic case where
> the "doctest" does *not* provide clarity over a "traditional" 'unittest'
> style test, IMNSHO.

It is often clearer to show the contents of a dict than making an assertion.
In those cases where it's not, you can make a unittest style assertion, as in:

 >>> thisdict == thatdict
True

This is really just a matter of knowing how to write the test.
Generally, when you want to show a dict sample, the way to do it
is with:

 >>> from zope.testing/doctestunit import pprint
 >>> pprint(thisdict)

This formats the dictionary nicely and, most importantly,
sorts the items before displaying it.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org


More information about the Zope-Dev mailing list