Merged in katarzynaanna/pytest (pull request #42)

Improved reporting
This commit is contained in:
holger krekel 2013-07-06 16:03:27 +02:00
commit a6f2af23fb
2 changed files with 29 additions and 14 deletions

View File

@ -44,7 +44,7 @@ def pytest_configure(config):
pass
else:
config._cleanup.append(lambda: newstdout.close())
assert stdout.encoding == newstdout.encoding
assert stdout.encoding == newstdout.encoding
stdout = newstdout
reporter = TerminalReporter(config, stdout)
@ -105,7 +105,7 @@ class TerminalReporter:
self.hasmarkup = self._tw.hasmarkup
def hasopt(self, char):
char = {'xfailed': 'x', 'skipped': 's'}.get(char,char)
char = {'xfailed': 'x', 'skipped': 's'}.get(char, char)
return char in self.reportchars
def write_fspath_result(self, fspath, res):
@ -154,7 +154,7 @@ class TerminalReporter:
def pytest_plugin_registered(self, plugin):
if self.config.option.traceconfig:
msg = "PLUGIN registered: %s" %(plugin,)
msg = "PLUGIN registered: %s" % (plugin,)
# XXX this event may happen during setup/teardown time
# which unfortunately captures our output here
# which garbles our output if we use self.write_line
@ -209,7 +209,7 @@ class TerminalReporter:
self.currentfspath = -2
def pytest_collection(self):
if not self.hasmarkup and self.config.option.verbose >=1:
if not self.hasmarkup and self.config.option.verbose >= 1:
self.write("collecting ... ", bold=True)
def pytest_collectreport(self, report):
@ -325,8 +325,8 @@ class TerminalReporter:
stack.append(col)
#if col.name == "()":
# continue
indent = (len(stack)-1) * " "
self._tw.line("%s%s" %(indent, col))
indent = (len(stack) - 1) * " "
self._tw.line("%s%s" % (indent, col))
def pytest_sessionfinish(self, exitstatus, __multicall__):
__multicall__.execute()
@ -452,9 +452,9 @@ class TerminalReporter:
if key: # setup/teardown reports have an empty key, ignore them
val = self.stats.get(key, None)
if val:
parts.append("%d %s" %(len(val), key))
parts.append("%d %s" % (len(val), key))
line = ", ".join(parts)
msg = "%s in %.2f seconds" %(line, session_duration)
msg = "%s in %.2f seconds" % (line, session_duration)
if self.verbosity >= 0:
markup = dict(bold=True)
if 'failed' in self.stats:
@ -462,6 +462,10 @@ class TerminalReporter:
else:
markup['green'] = True
self.write_sep("=", msg, **markup)
if self.verbosity == -1:
if line:
self.write("%s, " % line)
self.write("time: %.2f seconds\n" % session_duration)
#else:
# self.write_line(msg, bold=True)
@ -475,7 +479,7 @@ class TerminalReporter:
if m:
l.append("-m %r" % m)
if l:
self.write_sep("=", "%d tests deselected by %r" %(
self.write_sep("=", "%d tests deselected by %r" % (
len(self.stats['deselected']), " ".join(l)), bold=True)
def repr_pythonversion(v=None):

View File

@ -1,7 +1,7 @@
"""
terminal reporting of the full testing process.
"""
import pytest,py
import pytest, py
import sys
from _pytest.terminal import TerminalReporter, repr_pythonversion, getreportopt
@ -32,7 +32,7 @@ def pytest_generate_tests(metafunc):
metafunc.addcall(id="verbose",
funcargs={'option': Option(verbose=True)})
metafunc.addcall(id="quiet",
funcargs={'option': Option(verbose=-1)})
funcargs={'option': Option(verbose= -1)})
metafunc.addcall(id="fulltrace",
funcargs={'option': Option(fulltrace=True)})
@ -286,7 +286,7 @@ def test_repr_python_version(monkeypatch):
try:
monkeypatch.setattr(sys, 'version_info', (2, 5, 1, 'final', 0))
assert repr_pythonversion() == "2.5.1-final-0"
py.std.sys.version_info = x = (2,3)
py.std.sys.version_info = x = (2, 3)
assert repr_pythonversion() == str(x)
finally:
monkeypatch.undo() # do this early as pytest can get confused
@ -411,7 +411,7 @@ class TestTerminalFunctional:
verinfo = ".".join(map(str, py.std.sys.version_info[:3]))
result.stdout.fnmatch_lines([
"*===== test session starts ====*",
"platform %s -- Python %s*" %(
"platform %s -- Python %s*" % (
py.std.sys.platform, verinfo), # , py.std.sys.executable),
"*test_header_trailer_info.py .",
"=* 1 passed in *.[0-9][0-9] seconds *=",
@ -473,6 +473,17 @@ class TestTerminalFunctional:
assert 'test session starts' not in s
assert p1.basename not in s
assert "===" not in s
assert "passed" in s
def test_more_quiet_reporting(self, testdir):
p1 = testdir.makepyfile("def test_pass(): pass")
result = testdir.runpytest(p1, '-qq')
s = result.stdout.str()
assert 'test session starts' not in s
assert p1.basename not in s
assert "===" not in s
assert "passed" not in s
def test_fail_extra_reporting(testdir):
p = testdir.makepyfile("def test_this(): assert 0")
@ -679,5 +690,5 @@ def test_tbstyle_native_setup_error(testdir):
""")
result = testdir.runpytest("--tb=native")
result.stdout.fnmatch_lines([
'*File *test_tbstyle_native_setup_error.py", line *, in setup_error_fixture*'
'*File *test_tbstyle_native_setup_error.py", line *, in setup_error_fixture*'
])