use item's own fspath when doing progress reporting, fixes #31

--HG--
branch : 1.0.x
This commit is contained in:
holger krekel 2009-08-17 16:45:52 +02:00
parent d2f497084e
commit 822b69a4e8
3 changed files with 42 additions and 16 deletions

View File

@ -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)

View File

@ -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
#

View File

@ -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