From 822b69a4e8d7d0a7b7854c16b347d07666b66377 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 17 Aug 2009 16:45:52 +0200 Subject: [PATCH] use item's own fspath when doing progress reporting, fixes #31 --HG-- branch : 1.0.x --- py/test/plugin/pytest_default.py | 4 ++-- py/test/plugin/pytest_terminal.py | 23 ++++++++++++++----- py/test/plugin/test_pytest_terminal.py | 31 +++++++++++++++++++------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/py/test/plugin/pytest_default.py b/py/test/plugin/pytest_default.py index 047ea82ca..bc7d6cb8d 100644 --- a/py/test/plugin/pytest_default.py +++ b/py/test/plugin/pytest_default.py @@ -99,8 +99,8 @@ def pytest_configure(config): setsession(config) if config.option.version: p = py.path.local(py.__file__).dirpath() - print "This is py.test version %s, imported from %s" % ( - py.__version__, p) + sys.stderr.write("This is py.test version %s, imported from %s\n" % + (py.__version__, p)) sys.exit(0) #xxxloadplugins(config) diff --git a/py/test/plugin/pytest_terminal.py b/py/test/plugin/pytest_terminal.py index 80f7020ea..8d905b4e0 100644 --- a/py/test/plugin/pytest_terminal.py +++ b/py/test/plugin/pytest_terminal.py @@ -181,8 +181,8 @@ class TerminalReporter: else: # ensure that the path is printed before the # 1st test of a module starts running - fspath, lineno, msg = self._getreportinfo(item) - self.write_fspath_result(fspath, "") + + self.write_fspath_result(self._getfspath(item), "") def pytest__teardown_final_logerror(self, report): self.stats.setdefault("error", []).append(report) @@ -199,8 +199,7 @@ class TerminalReporter: markup = {} self.stats.setdefault(cat, []).append(rep) if not self.config.option.verbose: - fspath, lineno, msg = self._getreportinfo(rep.item) - self.write_fspath_result(fspath, letter) + self.write_fspath_result(self._getfspath(rep.item), letter) else: line = self._reportinfoline(rep.item) if not hasattr(rep, 'node'): @@ -288,8 +287,13 @@ class TerminalReporter: self.write_line("### Watching: %s" %(rootdir,), bold=True) def _reportinfoline(self, item): + collect_fspath = self._getfspath(item) fspath, lineno, msg = self._getreportinfo(item) - if fspath: + if fspath and fspath != collect_fspath: + fspath = "%s <- %s" % ( + self.curdir.bestrelpath(collect_fspath), + self.curdir.bestrelpath(fspath)) + elif fspath: fspath = self.curdir.bestrelpath(fspath) if lineno is not None: lineno += 1 @@ -298,7 +302,7 @@ class TerminalReporter: elif fspath and msg: line = "%(fspath)s: %(msg)s" elif fspath and lineno: - line = "%(fspath)s:%(lineno)s" + line = "%(fspath)s:%(lineno)s %(extrapath)s" else: line = "[noreportinfo]" return line % locals() + " " @@ -322,6 +326,13 @@ class TerminalReporter: item.__reportinfo = reportinfo return reportinfo + def _getfspath(self, item): + try: + return item.fspath + except AttributeError: + fspath, lineno, msg = self._getreportinfo(item) + return fspath + # # summaries for sessionfinish # diff --git a/py/test/plugin/test_pytest_terminal.py b/py/test/plugin/test_pytest_terminal.py index 509d90bdb..6b4ddff56 100644 --- a/py/test/plugin/test_pytest_terminal.py +++ b/py/test/plugin/test_pytest_terminal.py @@ -209,10 +209,6 @@ class TestTerminal: item = testdir.getitem("def test_func(): pass") tr = TerminalReporter(item.config, file=linecomp.stringio) item.config.pluginmanager.register(tr) - tr.config.hook.pytest_itemstart(item=item) - linecomp.assert_contains_lines([ - "*ABCDE " - ]) tr.config.option.verbose = True tr.config.hook.pytest_itemstart(item=item) linecomp.assert_contains_lines([ @@ -227,16 +223,35 @@ class TestTerminal: item.config.pluginmanager.register(Plugin()) tr = TerminalReporter(item.config, file=linecomp.stringio) item.config.pluginmanager.register(tr) - tr.config.hook.pytest_itemstart(item=item) - linecomp.assert_contains_lines([ - "*FGHJ " - ]) tr.config.option.verbose = True tr.config.hook.pytest_itemstart(item=item) linecomp.assert_contains_lines([ "*FGHJ:43: custom*" ]) + def test_itemreport_subclasses_show_subclassed_file(self, testdir): + p1 = testdir.makepyfile(test_p1=""" + class BaseTests: + def test_p1(self): + pass + class TestClass(BaseTests): + pass + """) + p2 = testdir.makepyfile(test_p2=""" + from test_p1 import BaseTests + class TestMore(BaseTests): + pass + """) + result = testdir.runpytest(p2) + assert result.stdout.fnmatch_lines([ + "*test_p2.py .", + "*1 passed*", + ]) + result = testdir.runpytest("-v", p2) + result.stdout.fnmatch_lines([ + "*test_p2.py <- test_p1.py:2: TestMore.test_p1*", + ]) + def test_keyboard_interrupt_dist(self, testdir, option): p = testdir.makepyfile(""" raise KeyboardInterrupt