[svn r62287] By default cut traceback such that py lib code does not appear

test tracebacks.

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-01 12:24:52 +01:00
parent 9d9a94ce00
commit d47ae0dc8d
9 changed files with 26 additions and 11 deletions

View File

@ -108,6 +108,15 @@ class TestTraceback_f_g_h:
newtraceback = traceback.cut(path=path, lineno=firstlineno+2) newtraceback = traceback.cut(path=path, lineno=firstlineno+2)
assert len(newtraceback) == 1 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): def test_traceback_filter(self):
traceback = self.excinfo.traceback traceback = self.excinfo.traceback
ntraceback = traceback.filter() ntraceback = traceback.filter()

View File

@ -118,7 +118,7 @@ class Traceback(list):
else: else:
list.__init__(self, tb) 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 """ return a Traceback instance wrapping part of this Traceback
by provding any combination of path, lineno and firstlineno, the by provding any combination of path, lineno and firstlineno, the
@ -129,7 +129,11 @@ class Traceback(list):
with handling of the exception/traceback) with handling of the exception/traceback)
""" """
for x in self: 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 (lineno is None or x.lineno == lineno) and
(firstlineno is None or x.frame.code.firstlineno == firstlineno)): (firstlineno is None or x.frame.code.firstlineno == firstlineno)):
return Traceback(x._rawentry) return Traceback(x._rawentry)

View File

@ -50,6 +50,7 @@ class TestMultiCall:
res = call.execute(firstresult=True) res = call.execute(firstresult=True)
assert res == 2 assert res == 2
class TestPyPlugins: class TestPyPlugins:
def test_MultiCall(self): def test_MultiCall(self):
plugins = PyPlugins() plugins = PyPlugins()

View File

@ -3,7 +3,8 @@ import py
class DoctestPlugin: class DoctestPlugin:
def pytest_addoption(self, parser): def pytest_addoption(self, parser):
parser.addoption("--doctest-modules", parser.addoption("--doctest-modules",
action="store_true", dest="doctestmodules") action="store_true", default=False,
dest="doctestmodules")
def pytest_collect_file(self, path, parent): def pytest_collect_file(self, path, parent):
if path.ext == ".py": if path.ext == ".py":

View File

@ -371,10 +371,10 @@ def test_eventrecorder():
assert numskipped == 1 assert numskipped == 1
assert numfailed == 2 assert numfailed == 2
recorder.unregister()
recorder.clear() recorder.clear()
assert not recorder.events assert not recorder.events
assert not recorder.getfailures() assert not recorder.getfailures()
recorder.unregister()
bus.notify("itemtestreport", rep) bus.notify("itemtestreport", rep)
assert not recorder.events assert not recorder.events
assert not recorder.getfailures() assert not recorder.getfailures()

View File

@ -42,4 +42,5 @@ def test_pyfuncarg(testdir):
plugin.pytest_configure(item._config) plugin.pytest_configure(item._config)
p = plugin.pytest_pyfuncarg_tmpdir(item) p = plugin.pytest_pyfuncarg_tmpdir(item)
assert p.check() assert p.check()
assert p.basename.endswith("test_func") bn = p.basename.strip("0123456789")
assert bn.endswith("test_func")

View File

@ -19,6 +19,7 @@ a tree of collectors and test items that this modules provides::
import py import py
from py.__.test.collect import configproperty, warnoldcollect from py.__.test.collect import configproperty, warnoldcollect
from py.__.code.source import findsource from py.__.code.source import findsource
pydir = py.path.local(py.__file__).dirpath()
class PyobjMixin(object): class PyobjMixin(object):
def obj(): def obj():
@ -273,6 +274,8 @@ class FunctionMixin(PyobjMixin):
ntraceback = traceback.cut(path=path, firstlineno=firstlineno) ntraceback = traceback.cut(path=path, firstlineno=firstlineno)
if ntraceback == traceback: if ntraceback == traceback:
ntraceback = ntraceback.cut(path=path) ntraceback = ntraceback.cut(path=path)
if ntraceback == traceback:
ntraceback = ntraceback.cut(excludepath=pydir)
traceback = ntraceback.filter() traceback = ntraceback.filter()
return traceback return traceback

View File

@ -1,7 +1,6 @@
import py import py
import marshal import marshal
from py.__.test.outcome import Skipped
class TestRaises: class TestRaises:
def test_raises(self): 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)
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(): def test_importorskip():
from py.__.test.outcome import Skipped
try: try:
sys = py.test.importorskip("sys") sys = py.test.importorskip("sys")
assert sys == py.std.sys assert sys == py.std.sys

View File

@ -271,3 +271,4 @@ class TestPytestPluginInteractions:
assert len(call.methods) == 3 assert len(call.methods) == 3
results = call.execute() results = call.execute()
assert results == [1,2,2] assert results == [1,2,2]