Message43382
Logged In: YES
user_id=21477
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)
|
|
Date |
User |
Action |
Args |
2007-08-23 15:22:16 | admin | link | issue722638 messages |
2007-08-23 15:22:16 | admin | create | |
|