summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2009-07-29 10:40:44 +0200
committerAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2009-07-29 10:40:44 +0200
commit12c9630cc47b27c1a9e910695e302037e8e2b642 (patch)
tree61f955c32d15fd88db87da38ccebcc0480fec4ad
parentfd15c8efa8b1344aa05ef4531e65df698b1b8679 (diff)
downloadlogilab-common-12c9630cc47b27c1a9e910695e302037e8e2b642.tar.gz
[testlib] simplify traceback manipulation (skip first frames corresponding to testlib functions)
-rw-r--r--ChangeLog1
-rw-r--r--testlib.py20
2 files changed, 13 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 11cc3c4..b0c8f5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@ ChangeLog for logilab.common
- #9764 add title to shellutils.ProgressBar
- #9796 new confirm function
+ * testlib: simplify traceback manipulation (skip first frames corresponding to testlib functions)
2009-07-17 -- 0.42.0
diff --git a/testlib.py b/testlib.py
index bd31670..444a4e7 100644
--- a/testlib.py
+++ b/testlib.py
@@ -45,6 +45,7 @@ from operator import itemgetter
from warnings import warn
from compiler.consts import CO_GENERATOR
from ConfigParser import ConfigParser
+from itertools import dropwhile
try:
from test import test_support
@@ -373,6 +374,15 @@ class SkipAwareTestResult(unittest._TextTestResult):
if self.pdbmode:
self.debuggers.append(self.pdbclass(sys.exc_info()[2]))
+
+ def _iter_valid_frames(self, frames):
+ """only consider non-testlib frames when formatting traceback"""
+ lgc_testlib = osp.abspath(__file__)
+ std_testlib = osp.abspath(unittest.__file__)
+ invalid = lambda fi: osp.abspath(fi[1]) in (lgc_testlib, std_testlib)
+ for frameinfo in dropwhile(invalid, frames):
+ yield frameinfo
+
def _exc_info_to_string(self, err, test):
"""Converts a sys.exc_info()-style tuple of values into a string.
@@ -384,13 +394,8 @@ class SkipAwareTestResult(unittest._TextTestResult):
output = ['Traceback (most recent call last)']
frames = inspect.getinnerframes(tb)
colorize = self.colorize
- # count number of relevant levels in the traceback: skip first since
- # it's our own _proceed function, and then start counting, using
- # unittest's heuristic
- nb_frames_skipped = self._count_relevant_tb_levels(tb.tb_next)
- for index, (frame, filename, lineno, funcname, ctx, ctxindex) in enumerate(frames):
- if not (0 < index <= nb_frames_skipped):
- continue
+ frames = enumerate(self._iter_valid_frames(frames))
+ for index, (frame, filename, lineno, funcname, ctx, ctxindex) in frames:
filename = osp.abspath(filename)
if ctx is None: # pyc files or C extensions for instance
source = '<no source available>'
@@ -462,7 +467,6 @@ class SkipAwareTestResult(unittest._TextTestResult):
self.stream.writeln(self.separator2)
self.stream.writeln(err)
-
try:
output, errput = test.captured_output()
except AttributeError: