A better unittest

Thomas Heller theller at python.net
Wed Apr 16 13:39:57 EDT 2003


"Terry Reedy" <tjreedy at udel.edu> writes:

> "Thomas Heller" <theller at python.net> wrote in message
> news:n0iqy1zg.fsf at python.net...
> ======================================================================
> > FAIL: test_failUnlessEqual (__main__.FailingTests)
> > --------------------------------------------------------------------
> --
> > TestFailed: 0 != 1
> >   File "xunit.py", line 12, in test_failUnlessEqual
> >     self.failUnlessEqual(self.a, self.b)
> 
> I like having the actual values too.  It should make debugging an
> unexpected failure easier.

Actually, this is nothing that is new (as I also only discovered today).
You just have to use self.failUnlessEqual(x, y) instead of
self.failUnless(x == y).

>   But what if each value is more that a few
> bytes?  Example (from my future plans): two lists of all permutations
> of range(8), one produced by an obvious recursion and the other by a
> much less obvious iteration.

You are right, this is a pain. In unittest, in doctest, whereever
long lists are printed. It gets somewhat easier for the eye if
pprint.pprint() is used instead.


> Hmmm.  What I would really like is a structure comparison function
> that spit out the first difference found  so I did not have to print
> each and compare by eye.  That is not directly in the scope of your
> problem, but it would be the most useful succinct display.

As you say, it's a different problem.
The patches simply rearrange the output.

Thomas




More information about the Python-list mailing list