New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better output for unittest #38312
Comments
This patch enables more useful output for unittests: If If a test failes, the output is something like this: ======================================== ======================================== Before, this was printed: ======================================== 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 This has shortly been discussed on c.l.p, response was |
Logged In: YES Attaching new version of the patch (unittest-2.diff). This ====================================================================== ====================================================================== ---------------------------------------------------------------------- |
Logged In: YES I like the new output, personally. I am +1 on letting Thomas add the |
Logged In: YES This behaviour of trimming the traceback was implemented in a previous |
Logged In: YES What a pity! What exactly does not work in Jython? Before giving up on this, there are at least two ways to
How are the chances for one of this? |
Logged In: YES After investigation, this seems to work with Jython (though not JPython, In general I've been trying hard to keep 'unittest.py' vanilla, since a lot In that sense, I'm not sure if it's worth changing the message. |
Logged In: YES Last attempt to convince you: I could try to port the If you still reject the patch (you're the unittest boss), |
Logged In: YES I would like to see Thomas's patch or some comformant |
Logged In: YES I'm split. The current output when assertRaises fails is a |
Logged In: YES That's exactly how I was feeling. When an assertRaises test And that's what this patch tries to fix. I don't want to see For the output of a failed assertRaises, see the first |
Logged In: YES That's why I'm split: I do like the new *messages* better |
Logged In: YES Assigned to Steve for pronouncement (didn't he already |
Logged In: YES I'm looking at all this and will certainly incorporate some of
|
Logged In: YES I've brought the patch up to date with current cvs, and made The patch has been discussed in this thread on python-dev: New patch attached: unittest-3.diff |
Logged In: YES Attached a test script together with what is printed before test_sample.py |
Logged In: YES I love it! We're all waiting for a +1 from Steve so this can be checked |
Logged In: YES Cool, although after some thought I again like the |
Logged In: YES Thomas, Can you make the TestFailed issue a separate |
Logged In: YES Hi all,
I've accepted this patch, with some modifications, and checked it into
both Pyunit and Python CVS.
If the callable passed to assertRaises() throws an exception other than
the one expected, the test result should really be ERROR; the proposed
changes to assertRaises() resulted in tracebacks for such unexpected
exceptions being lost, since only the exception name and message were
formatted into the failure string. I've therefore left the logic there as it
was.
Also, rather than hard-code the number of levels of traceback to skip,
the changes I have checked in automatically determine the number of
levels to skip. Please take a look and tell me if the trick I have used is
excessively horrible.
As for the separate TestFailed issue, for me this is not terribly attractive,
since I know that many people find it very convenient to use the 'assert'
keyword in their test code. (Note that by setting the 'failureException'
attribute of your test cases, you can use an exception other than
AssertionError.)
For your reference, the output of Thomas' sample test script is now as
follows:
FFE
======================================================================
ERROR: test_4 (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "heller.py", line 21, in test_4
self.assertRaises(ValueError, getattr, self, "spam")
File "/export/home/steve/projects/pyunit/pyunit-cvs/unittest.py", line
319, in failUnlessRaises
callableObj(*args, **kwargs)
AttributeError: 'MyTestCase' object has no attribute 'spam'
======================================================================
FAIL: test_1 (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "heller.py", line 6, in test_1
self.do_this()
File "heller.py", line 9, in do_this
self.do_that()
File "heller.py", line 12, in do_that
self.failUnlessEqual(1, 2)
AssertionError: 1 != 2
======================================================================
FAIL: test_3 (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "heller.py", line 17, in test_3
self.assertRaises(AttributeError, getattr, self, "silly")
AssertionError: AttributeError not raised
----------------------------------------------------------------------
Ran 3 tests in 0.008s
FAILED (failures=2, errors=1) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: