[svn r62287] By default cut traceback such that py lib code does not appear
test tracebacks. --HG-- branch : trunk
This commit is contained in:
parent
9d9a94ce00
commit
d47ae0dc8d
|
@ -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)
|
||||
|
|
|
@ -49,6 +49,7 @@ class TestMultiCall:
|
|||
call = MultiCall([n, m])
|
||||
res = call.execute(firstresult=True)
|
||||
assert res == 2
|
||||
|
||||
|
||||
class TestPyPlugins:
|
||||
def test_MultiCall(self):
|
||||
|
|
|
@ -3,7 +3,8 @@ import py
|
|||
class DoctestPlugin:
|
||||
def pytest_addoption(self, parser):
|
||||
parser.addoption("--doctest-modules",
|
||||
action="store_true", dest="doctestmodules")
|
||||
action="store_true", default=False,
|
||||
dest="doctestmodules")
|
||||
|
||||
def pytest_collect_file(self, path, parent):
|
||||
if path.ext == ".py":
|
||||
|
|
|
@ -371,10 +371,10 @@ def test_eventrecorder():
|
|||
assert numskipped == 1
|
||||
assert numfailed == 2
|
||||
|
||||
recorder.unregister()
|
||||
recorder.clear()
|
||||
assert not recorder.events
|
||||
assert not recorder.getfailures()
|
||||
recorder.unregister()
|
||||
bus.notify("itemtestreport", rep)
|
||||
assert not recorder.events
|
||||
assert not recorder.getfailures()
|
||||
|
|
|
@ -42,4 +42,5 @@ def test_pyfuncarg(testdir):
|
|||
plugin.pytest_configure(item._config)
|
||||
p = plugin.pytest_pyfuncarg_tmpdir(item)
|
||||
assert p.check()
|
||||
assert p.basename.endswith("test_func")
|
||||
bn = p.basename.strip("0123456789")
|
||||
assert bn.endswith("test_func")
|
||||
|
|
|
@ -19,6 +19,7 @@ a tree of collectors and test items that this modules provides::
|
|||
import py
|
||||
from py.__.test.collect import configproperty, warnoldcollect
|
||||
from py.__.code.source import findsource
|
||||
pydir = py.path.local(py.__file__).dirpath()
|
||||
|
||||
class PyobjMixin(object):
|
||||
def obj():
|
||||
|
@ -273,6 +274,8 @@ class FunctionMixin(PyobjMixin):
|
|||
ntraceback = traceback.cut(path=path, firstlineno=firstlineno)
|
||||
if ntraceback == traceback:
|
||||
ntraceback = ntraceback.cut(path=path)
|
||||
if ntraceback == traceback:
|
||||
ntraceback = ntraceback.cut(excludepath=pydir)
|
||||
traceback = ntraceback.filter()
|
||||
return traceback
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
import py
|
||||
import marshal
|
||||
from py.__.test.outcome import Skipped
|
||||
|
||||
class TestRaises:
|
||||
def test_raises(self):
|
||||
|
@ -59,12 +58,8 @@ def test_deprecated_explicit_call():
|
|||
py.test.deprecated_call(dep_explicit, 0)
|
||||
py.test.deprecated_call(dep_explicit, 0)
|
||||
|
||||
def test_skip_simple():
|
||||
excinfo = py.test.raises(Skipped, 'py.test.skip("xxx")')
|
||||
assert excinfo.traceback[-1].frame.code.name == "skip"
|
||||
assert excinfo.traceback[-1].ishidden()
|
||||
|
||||
def test_importorskip():
|
||||
from py.__.test.outcome import Skipped
|
||||
try:
|
||||
sys = py.test.importorskip("sys")
|
||||
assert sys == py.std.sys
|
||||
|
|
|
@ -271,3 +271,4 @@ class TestPytestPluginInteractions:
|
|||
assert len(call.methods) == 3
|
||||
results = call.execute()
|
||||
assert results == [1,2,2]
|
||||
|
||||
|
|
Loading…
Reference in New Issue