Opened 9 years ago

Last modified 6 years ago

#4127 enhancement new

trial report unittest module in tracebacks

Reported by: marco.giusti@… Owned by:
Priority: normal Milestone:
Component: trial Keywords:
Cc: Branch:
Author:

Description

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)

Change History (3)

comment:1 Changed 9 years ago by marco.giusti@…

Summary: trial report its module in tracebackstrial report unittest module in tracebacks

comment:2 Changed 8 years ago by <automation>

Owner: Jonathan Lange deleted

comment:3 Changed 6 years ago by Julian Berman

There isn't a terribly reasonable way to do this until http://bugs.python.org/issue1705520 lands, but what other test runners do is the hacky thing mentioned on that ticket.

Note: See TracTickets for help on using tickets.