[Python-Dev] unittest output

Guido van Rossum guido at python.org
Wed Dec 3 10:05:16 EST 2003

> http://www.python.org/sf/722638 

> > A refinement could be to make the output *look* like a (short)
> > traceback as printed by the traceback module even in the failure case;
> > this would address Steve's issue tht IDEs find lines in the code via
> > the traceback.  And there should be a command line switch and an
> > environment variable to show the full traceback in all cases.
> The patch does this, also.  My original usecase was that I wanted Xemacs
> to automatically go to the line of the failed test, and not inside the
> unittest source line where the exception was raised.

Right.  I have the same use case.

> And the patch *only* suppresses the deepest frame (that inside the
> unittest source code), if the traceback is n levels deep, n-1 levels
> are printed.

Ah.  I didn't look at the patch, but in your description you also
suppress the line

Traceback (most recent call last):

*and* you only show a one-item traceback, so that wasn't very clear.

> At least this was my intention, if the patch has a chance to make it in,
> I'll try it again, and bring it up to date if needed.

Please do -- feel free to add a pointer to this thread to the SF tracker.

> (Another question is this: is raising an exception the right thing to do
> when a test fails? I'm not so sure, although changing this would be a
> much bigger change...)

Well, we're stuck with that because everybody writes tests that
contain many assertEqual() (of failIf() etc.) calls in a row and
expects the control flow to end if one such call fails.  Without
raising an exception the rest of the test function would be executed
regardless, and that would probably raise the probability of
unexpected exceptions dramatically.  So don't bring that issue up in
the same SF item...

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list