From d47ae0dc8d47c653082f0b7219c414395ad47f4b Mon Sep 17 00:00:00 2001 From: hpk Date: Sun, 1 Mar 2009 12:24:52 +0100 Subject: [PATCH] [svn r62287] By default cut traceback such that py lib code does not appear test tracebacks. --HG-- branch : trunk --- py/code/testing/test_excinfo.py | 9 +++++++++ py/code/traceback2.py | 8 ++++++-- py/misc/testing/test_com.py | 1 + py/test/plugin/pytest_doctest.py | 3 ++- py/test/plugin/pytest_pytester.py | 2 +- py/test/plugin/pytest_tmpdir.py | 3 ++- py/test/pycollect.py | 3 +++ py/test/testing/test_outcome.py | 7 +------ py/test/testing/test_pytestplugin.py | 1 + 9 files changed, 26 insertions(+), 11 deletions(-) diff --git a/py/code/testing/test_excinfo.py b/py/code/testing/test_excinfo.py index 28a314432..94d31e26b 100644 --- a/py/code/testing/test_excinfo.py +++ b/py/code/testing/test_excinfo.py @@ -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() diff --git a/py/code/traceback2.py b/py/code/traceback2.py index d5d40e8be..0d715a4ed 100644 --- a/py/code/traceback2.py +++ b/py/code/traceback2.py @@ -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) diff --git a/py/misc/testing/test_com.py b/py/misc/testing/test_com.py index 6d2aa31ef..84fa0b412 100644 --- a/py/misc/testing/test_com.py +++ b/py/misc/testing/test_com.py @@ -49,6 +49,7 @@ class TestMultiCall: call = MultiCall([n, m]) res = call.execute(firstresult=True) assert res == 2 + class TestPyPlugins: def test_MultiCall(self): diff --git a/py/test/plugin/pytest_doctest.py b/py/test/plugin/pytest_doctest.py index 204fe173d..e4e32661d 100644 --- a/py/test/plugin/pytest_doctest.py +++ b/py/test/plugin/pytest_doctest.py @@ -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": diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index 9797d0f91..8827c4531 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.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() diff --git a/py/test/plugin/pytest_tmpdir.py b/py/test/plugin/pytest_tmpdir.py index 53b7a8000..ad2520517 100644 --- a/py/test/plugin/pytest_tmpdir.py +++ b/py/test/plugin/pytest_tmpdir.py @@ -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") diff --git a/py/test/pycollect.py b/py/test/pycollect.py index 6b7cfb2c9..30a44217c 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -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 diff --git a/py/test/testing/test_outcome.py b/py/test/testing/test_outcome.py index 71800d5c8..9c1d5115f 100644 --- a/py/test/testing/test_outcome.py +++ b/py/test/testing/test_outcome.py @@ -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 diff --git a/py/test/testing/test_pytestplugin.py b/py/test/testing/test_pytestplugin.py index c3f41c6ca..f9e813a78 100644 --- a/py/test/testing/test_pytestplugin.py +++ b/py/test/testing/test_pytestplugin.py @@ -271,3 +271,4 @@ class TestPytestPluginInteractions: assert len(call.methods) == 3 results = call.execute() assert results == [1,2,2] +