trial report its module in tracebacks

[email protected] Sun, 22 Nov 2009 17:14:05 -0000
Newsgroups gmane.comp.python.twisted.bugs
Message-ID <[email protected]>
New submission from [email protected] <None>:

Standard python unittest hides unhelpful tracebacks using 'levels':

{{{
...
__unittest = 1
...

class TestResult:

    ...

    def _exc_info_to_string(self, err, test):
        """Converts a sys.exc_info()-style tuple of values into a string."""
        exctype, value, tb = err
        # Skip test runner traceback levels
        while tb and self._is_relevant_tb_level(tb):
            tb = tb.tb_next
        if exctype is test.failureException:
            # Skip assert*() traceback levels
            length = self._count_relevant_tb_levels(tb)
            return ''.join(traceback.format_exception(exctype, value, tb, length))
        return ''.join(traceback.format_exception(exctype, value, tb))

    def _is_relevant_tb_level(self, tb):
        return '__unittest' in tb.tb_frame.f_globals
...
}}}

implementing somewhat similar makes tracebacks more clear and easies output parsing.

here the outputs using trial and unittest:

== trial ==

{{{
test
  TestCase
    testThatFails ...                                                    [FAIL]

===============================================================================
[FAIL]: test.TestCase.testThatFails

Traceback (most recent call last):
  File "/usr/lib/python2.5/unittest.py", line 260, in run
    testMethod()
  File "/home/nohero/test.py", line 6, in testThatFails
    self.assert_(False)
exceptions.AssertionError: 
-------------------------------------------------------------------------------
Ran 1 tests in 0.057s

FAILED (failures=1)
}}}

== unittest ==
{{{
F
======================================================================
FAIL: testThatFails (__main__.TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test.py", line 6, in testThatFails
    self.assert_(False)
AssertionError

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)
}}}

----------
Type     : enhancement
Component: trial
Keywords : 
Priority : normal
Nosy     : 
----------
http://twistedmatrix.com/trac/ticket/4127