From 5251653fc330409e9fecd7b2af0f36157d1bb7d9 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 4 Nov 2010 23:21:23 +0100 Subject: [PATCH] remove pytest_report_iteminfo hook, i strongly guess nobody needs or uses it. --- pytest/hookspec.py | 10 +--------- pytest/plugin/nose.py | 13 ------------- pytest/plugin/python.py | 25 ++++++++++++++++++------- pytest/plugin/runner.py | 2 +- pytest/plugin/session.py | 3 --- testing/plugin/test_python.py | 12 ------------ testing/plugin/test_session.py | 10 ---------- testing/plugin/test_terminal.py | 2 +- 8 files changed, 21 insertions(+), 56 deletions(-) diff --git a/pytest/hookspec.py b/pytest/hookspec.py index 236023d56..f27728baa 100644 --- a/pytest/hookspec.py +++ b/pytest/hookspec.py @@ -20,7 +20,7 @@ def pytest_cmdline_parse(pluginmanager, args): pytest_cmdline_parse.firstresult = True def pytest_addoption(parser): - """add optparse-style options and ini-style config values via calls + """add optparse-style options and ini-style config values via calls to ``parser.addoption`` and ``parser.addini(...)``. """ @@ -194,14 +194,6 @@ pytest_report_teststatus.firstresult = True def pytest_terminal_summary(terminalreporter): """ add additional section in terminal summary reporting. """ -def pytest_report_iteminfo(item): - """ return (fspath, lineno, domainpath) location info for the item. - the information is used for result display and to sort tests. - fspath,lineno: file and linenumber of source of item definition. - domainpath: custom id - e.g. for python: dotted import address - """ -pytest_report_iteminfo.firstresult = True - # ------------------------------------------------------------------------- # doctest hooks # ------------------------------------------------------------------------- diff --git a/pytest/plugin/nose.py b/pytest/plugin/nose.py index 91e6e79b1..a94a8a209 100644 --- a/pytest/plugin/nose.py +++ b/pytest/plugin/nose.py @@ -49,19 +49,6 @@ def pytest_runtest_makereport(__multicall__, item, call): call2 = call.__class__(lambda: py.test.skip(str(call.excinfo.value)), call.when) call.excinfo = call2.excinfo -def pytest_report_iteminfo(item): - # nose 0.11.1 uses decorators for "raises" and other helpers. - # for reporting progress by filename we fish for the filename - if isinstance(item, py.test.collect.Function): - obj = item.obj - if hasattr(obj, 'compat_co_firstlineno'): - fn = sys.modules[obj.__module__].__file__ - if fn.endswith(".pyc"): - fn = fn[:-1] - #assert 0 - #fn = inspect.getsourcefile(obj) or inspect.getfile(obj) - lineno = obj.compat_co_firstlineno - return py.path.local(fn), lineno, obj.__module__ def pytest_runtest_setup(item): if isinstance(item, (py.test.collect.Function)): diff --git a/pytest/plugin/python.py b/pytest/plugin/python.py index b2cac8289..192eed823 100644 --- a/pytest/plugin/python.py +++ b/pytest/plugin/python.py @@ -123,8 +123,19 @@ class PyobjMixin(object): return self._fslineno def reportinfo(self): - fspath, lineno = self._getfslineno() - modpath = self.getmodpath() + obj = self.obj + if hasattr(obj, 'compat_co_firstlineno'): + # nose compatibility + fspath = sys.modules[obj.__module__].__file__ + if fspath.endswith(".pyc"): + fspath = fspath[:-1] + #assert 0 + #fn = inspect.getsourcefile(obj) or inspect.getfile(obj) + lineno = obj.compat_co_firstlineno + modpath = obj.__module__ + else: + fspath, lineno = self._getfslineno() + modpath = self.getmodpath() return fspath, lineno, modpath class PyCollectorMixin(PyobjMixin, pytest.collect.Collector): @@ -501,16 +512,16 @@ class Metafunc: :arg funcargs: argument keyword dictionary used when invoking the test function. - :arg id: used for reporting and identification purposes. If you + :arg id: used for reporting and identification purposes. If you don't supply an `id` the length of the currently list of calls to the test function will be used. :arg param: will be exposed to a later funcarg factory invocation through the ``request.param`` attribute. Setting it (instead of directly providing a ``funcargs`` ditionary) is called - *indirect parametrization*. Indirect parametrization is - preferable if test values are expensive to setup or can - only be created after certain fixtures or test-run related + *indirect parametrization*. Indirect parametrization is + preferable if test values are expensive to setup or can + only be created after certain fixtures or test-run related initialization code has been run. """ assert funcargs is None or isinstance(funcargs, dict) @@ -593,7 +604,7 @@ class FuncargRequest: def applymarker(self, marker): """ apply a marker to a single test function invocation. This method is useful if you don't want to have a keyword/marker - on all function invocations. + on all function invocations. :arg marker: a :py:class:`pytest.plugin.mark.MarkDecorator` object created by a call to ``py.test.mark.NAME(...)``. diff --git a/pytest/plugin/runner.py b/pytest/plugin/runner.py index cc3b9a9f2..877d20cfb 100644 --- a/pytest/plugin/runner.py +++ b/pytest/plugin/runner.py @@ -41,7 +41,7 @@ def getitemnodeinfo(item): try: return item._nodeinfo except AttributeError: - location = item.ihook.pytest_report_iteminfo(item=item) + location = item.reportinfo() location = (str(location[0]), location[1], str(location[2])) nodenames = tuple(item.listnames()) nodeid = item.collection.getid(item) diff --git a/pytest/plugin/session.py b/pytest/plugin/session.py index 7628bca10..83edf0f04 100644 --- a/pytest/plugin/session.py +++ b/pytest/plugin/session.py @@ -116,9 +116,6 @@ def pytest_collect_directory(path, parent): return return Directory(path, parent=parent) -def pytest_report_iteminfo(item): - return item.reportinfo() - class Session(object): class Interrupted(KeyboardInterrupt): """ signals an interrupted test run. """ diff --git a/testing/plugin/test_python.py b/testing/plugin/test_python.py index 4de757549..05fd7bfbc 100644 --- a/testing/plugin/test_python.py +++ b/testing/plugin/test_python.py @@ -1061,18 +1061,6 @@ class TestReportInfo: nodeinfo = runner.getitemnodeinfo(item) assert nodeinfo.location == ("ABCDE", 42, "custom") - def test_itemreport_pytest_report_iteminfo(self, testdir, linecomp): - item = testdir.getitem("def test_func(): pass") - tup = "FGHJ", 42, "custom" - class Plugin: - def pytest_report_iteminfo(self, item): - return tup - item.config.pluginmanager.register(Plugin()) - runner = runner = item.config.pluginmanager.getplugin("runner") - nodeinfo = runner.getitemnodeinfo(item) - location = nodeinfo.location - assert location == tup - def test_func_reportinfo(self, testdir): item = testdir.getitem("def test_func(): pass") fspath, lineno, modpath = item.reportinfo() diff --git a/testing/plugin/test_session.py b/testing/plugin/test_session.py index 60be53f4b..85a5a7d4b 100644 --- a/testing/plugin/test_session.py +++ b/testing/plugin/test_session.py @@ -1,5 +1,4 @@ import py -from pytest.plugin.session import pytest_report_iteminfo class SessionTests: def test_basic_testitem_events(self, testdir): @@ -225,12 +224,3 @@ def test_exclude(testdir): result = testdir.runpytest("--ignore=hello", "--ignore=hello2") assert result.ret == 0 result.stdout.fnmatch_lines(["*1 passed*"]) - -def test_pytest_report_iteminfo(): - class FakeItem(object): - - def reportinfo(self): - return "-reportinfo-" - - res = pytest_report_iteminfo(FakeItem()) - assert res == "-reportinfo-" diff --git a/testing/plugin/test_terminal.py b/testing/plugin/test_terminal.py index 2fda994c9..f700a0b26 100644 --- a/testing/plugin/test_terminal.py +++ b/testing/plugin/test_terminal.py @@ -96,7 +96,7 @@ class TestTerminal: tr = TerminalReporter(item.config, file=linecomp.stringio) item.config.pluginmanager.register(tr) nodeid = item.collection.getid(item) - location = item.ihook.pytest_report_iteminfo(item=item) + location = item.reportinfo() tr.config.hook.pytest_runtest_logstart(nodeid=nodeid, location=location, fspath=str(item.fspath)) linecomp.assert_contains_lines([