[svn r62287] By default cut traceback such that py lib code does not appear
test tracebacks. --HG-- branch : trunk
This commit is contained in:
@@ -108,6 +108,15 @@ class TestTraceback_f_g_h:
|
||||
newtraceback = traceback.cut(path=path, lineno=firstlineno+2)
|
||||
assert len(newtraceback) == 1
|
||||
|
||||
def test_traceback_cut_excludepath(self, testdir):
|
||||
p = testdir.makepyfile("def f(): raise ValueError")
|
||||
excinfo = py.test.raises(ValueError, "p.pyimport().f()")
|
||||
print excinfo.traceback
|
||||
pydir = py.path.local(py.__file__).dirpath()
|
||||
newtraceback = excinfo.traceback.cut(excludepath=pydir)
|
||||
assert len(newtraceback) == 1
|
||||
assert newtraceback[0].frame.code.path == p
|
||||
|
||||
def test_traceback_filter(self):
|
||||
traceback = self.excinfo.traceback
|
||||
ntraceback = traceback.filter()
|
||||
|
||||
@@ -118,7 +118,7 @@ class Traceback(list):
|
||||
else:
|
||||
list.__init__(self, tb)
|
||||
|
||||
def cut(self, path=None, lineno=None, firstlineno=None):
|
||||
def cut(self, path=None, lineno=None, firstlineno=None, excludepath=None):
|
||||
""" return a Traceback instance wrapping part of this Traceback
|
||||
|
||||
by provding any combination of path, lineno and firstlineno, the
|
||||
@@ -129,7 +129,11 @@ class Traceback(list):
|
||||
with handling of the exception/traceback)
|
||||
"""
|
||||
for x in self:
|
||||
if ((path is None or x.frame.code.path == path) and
|
||||
code = x.frame.code
|
||||
codepath = code.path
|
||||
if ((path is None or codepath == path) and
|
||||
(excludepath is None or (hasattr(codepath, 'relto') and
|
||||
not codepath.relto(excludepath))) and
|
||||
(lineno is None or x.lineno == lineno) and
|
||||
(firstlineno is None or x.frame.code.firstlineno == firstlineno)):
|
||||
return Traceback(x._rawentry)
|
||||
|
||||
Reference in New Issue
Block a user