[Patches] [ python-Patches-722638 ] Better output for unittest

SourceForge.net noreply at sourceforge.net
Thu Oct 16 17:32:10 EDT 2003


Patches item #722638, was opened at 2003-04-16 19:49
Message generated for change (Comment added) made by purcell
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=722638&group_id=5470

Category: Library (Lib)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Thomas Heller (theller)
Assigned to: Steve Purcell (purcell)
Summary: Better output for unittest

Initial Comment:
This patch enables more useful output for unittests: If
a test crashes (raises an unexpected exception), a full
traceback is printed.

If a test failes, the output is something like this:

========================================
FAIL: test_failUnlessEqual (__main__.FailingTests)
----------------------------------------------------------------------
TestFailed: 0 != 1
  File "xunit.py", line 12, in test_failUnlessEqual
    self.failUnlessEqual(self.a, self.b)

========================================

Before, this was printed:

========================================
FAIL: test_failIfEqual (__main__.FailingTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "xunit.py", line 15, in test_failIfEqual
    self.failIfEqual(self.a, self.a)
  File "c:\python23\lib\unittest.py", line 300, in
failIfEqual
    raise self.failureException, AssertionError: 0 == 0

========================================

If needed, I can upload the test script I use, together
with the results before and after the patch.

This has shortly been discussed on c.l.p, response was
mostly positive.
http://tinyurl.com/9obf

----------------------------------------------------------------------

>Comment By: Steve Purcell (purcell)
Date: 2003-10-16 23:32

Message:
Logged In: YES 
user_id=21477

I'm looking at all this and will certainly incorporate some of 
the suggestions:  
  
- I'm +1 on the clearer message for assertRaises()  
- I'm +1 on clearer messages for _all_ assert*()/fail*() 
methods  
- The TestFailed exception doesn't really add much, since 
AssertionError works well already  
- I'm loathe to ever suppress tracebacks, or fiddle with them 
much: the traceback is the canonical way for IDEs to find 
lines in the code  

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-10-14 20:05

Message:
Logged In: YES 
user_id=11105

Assigned to Steve for pronouncement (didn't he already
comment on python-dev some time ago?)

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-05-06 22:27

Message:
Logged In: YES 
user_id=31435

That's why I'm split:  I do like the new *messages* better 
(their content), but I don't like losing the tracebacks.  
Sometimes it's a bug in the test driver-- or in 20 layers of test 
driver code --and sometimes it's even a bug in unittest itself.  
The traceback is a fundamental tool when things go wrong, 
so I'm never in favor of hiding parts of tracebacks (hiding could 
be appropriate if you *knew* the true cause isn't in the part 
you're hiding -- but you can't know that).

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-05-06 22:08

Message:
Logged In: YES 
user_id=11105

That's exactly how I was feeling. When an assertRaises test
failed, I usually inserted the call it made before this
line, to see the real traceback.

And that's what this patch tries to fix. I don't want to see
tracebacks when a test fails, I want a clear indication that
it failed (the patch prints "TestFailed" instead of
"Traceback:").

For the output of a failed assertRaises, see the first
comment I added. IMO it clearly says what which exception
was expected, and which one was raised.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-05-06 21:52

Message:
Logged In: YES 
user_id=31435

I'm split.  The current output when assertRaises fails is a 
frequent cause of head-scratching ("what?  it's complaining 
because ValueError got raised? ... no, it's complaining 
because ValueError wasn't raised? ...").  OTOH, I see no 
value in trimming the traceback.  Now that *could* be 
because the assertRaises output can be so confusing that 
we end up using the rest of the traceback to figure out what 
unittest is trying to tell us in those cases.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-06 09:11

Message:
Logged In: YES 
user_id=80475

I would like to see Thomas's patch or some comformant 
variant go in.  Usability problems are a bug.  Friendlier 
output makes it more likely that unittest will be used in 
the first place.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-04-25 14:52

Message:
Logged In: YES 
user_id=11105

Last attempt to convince you: I could try to port the
changes to Python 1.5, if you want to stay compatible.

If you still reject the patch (you're the unittest boss),
I'll have to live with subclassing unittest ;-)

----------------------------------------------------------------------

Comment By: Steve Purcell (purcell)
Date: 2003-04-25 14:37

Message:
Logged In: YES 
user_id=21477

After investigation, this seems to work with Jython (though not JPython, 
which didn't have tb_next etc.). 
 
In general I've been trying hard to keep 'unittest.py' vanilla, since a lot 
of people are still using it with Python 1.5 and even JPython. Hence the 
complete absence of string methods, list comprehensions and other new 
language features. Don't know if this policy makes sense in the longer 
term, but I value it right now. 
 
In that sense, I'm not sure if it's worth changing the message. 

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-04-25 14:05

Message:
Logged In: YES 
user_id=11105

What a pity! What exactly does not work in Jython?

Before giving up on this, there are at least two ways to
proceed:
- Behave as before in Jython, and use the better output in
CPython.
- Apply this patch only the the unittest version bundled
with CPython.

How are the chances for one of this?

----------------------------------------------------------------------

Comment By: Steve Purcell (purcell)
Date: 2003-04-25 13:52

Message:
Logged In: YES 
user_id=21477

This behaviour of trimming the traceback was implemented in a previous 
version of PyUnit, but dropped because it did not work with Jython. My 
aim is that the same 'unittest.py' should work out of the box with both 
CPython and Jython. 

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-04-20 04:57

Message:
Logged In: YES 
user_id=357491

I like the new output, personally.  I am +1 on letting Thomas add the 
changes.
Does this mean we no longer treat unittest as a separate project?

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2003-04-17 17:31

Message:
Logged In: YES 
user_id=11105

Attaching new version of the patch (unittest-2.diff). This
gives better output for failUnlessRaises, like this:

======================================================================
FAIL: test_failUnlessRaises (__main__.FailingTests)
----------------------------------------------------------------------
TestFailed: wrong exception, expected TypeError
got: 'ValueError: 10'
  File "xunit.py", line 18, in test_failUnlessRaises
    self.failUnlessRaises(TypeError, self._raise,
ValueError, 10)

======================================================================
FAIL: test_failUnlessRaises_2 (__main__.FailingTests)
----------------------------------------------------------------------
TestFailed: wrong exception, expected TypeError, IndexError,
or AttributeError
got: 'ValueError: 10'
  File "xunit.py", line 21, in test_failUnlessRaises_2
    self.failUnlessRaises((TypeError, IndexError,
AttributeError), self._raise, ValueError, 10)

----------------------------------------------------------------------

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=722638&group_id=5470



More information about the Patches mailing list