add terminalreporter.section|line methods to print extra information.

This commit is contained in:
holger krekel 2013-09-27 15:48:03 +02:00
parent 209a0cd5b2
commit 1fc466e8ac
5 changed files with 26 additions and 4 deletions

View File

@ -142,7 +142,9 @@ Bug fixes:
- better parametrize error messages, thanks Brianna Laugher - better parametrize error messages, thanks Brianna Laugher
- pytest_terminal_summary(terminalreporter) hooks can now use
".section(title)" and ".line(msg)" methods to print extra
information at the end of a test run.
Changes between 2.3.4 and 2.3.5 Changes between 2.3.4 and 2.3.5
----------------------------------- -----------------------------------

View File

@ -221,7 +221,7 @@ def pytest_report_teststatus(report):
pytest_report_teststatus.firstresult = True pytest_report_teststatus.firstresult = True
def pytest_terminal_summary(terminalreporter): def pytest_terminal_summary(terminalreporter):
""" add additional section in terminal summary reporting. """ """ add additional section in terminal summary reporting. """
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# doctest hooks # doctest hooks

View File

@ -100,7 +100,7 @@ class TerminalReporter:
self.startdir = self.curdir = py.path.local() self.startdir = self.curdir = py.path.local()
if file is None: if file is None:
file = py.std.sys.stdout file = py.std.sys.stdout
self._tw = py.io.TerminalWriter(file) self._tw = self.writer = py.io.TerminalWriter(file)
self.currentfspath = None self.currentfspath = None
self.reportchars = getreportopt(config) self.reportchars = getreportopt(config)
self.hasmarkup = self._tw.hasmarkup self.hasmarkup = self._tw.hasmarkup
@ -148,6 +148,12 @@ class TerminalReporter:
self.ensure_newline() self.ensure_newline()
self._tw.sep(sep, title, **markup) self._tw.sep(sep, title, **markup)
def section(self, title, sep="=", **kw):
self._tw.sep(sep, title, **kw)
def line(self, msg, **kw):
self._tw.line(msg, **kw)
def pytest_internalerror(self, excrepr): def pytest_internalerror(self, excrepr):
for line in str(excrepr).split("\n"): for line in str(excrepr).split("\n"):
self.write_line("INTERNALERROR> " + line) self.write_line("INTERNALERROR> " + line)
@ -179,6 +185,7 @@ class TerminalReporter:
res = self.config.hook.pytest_report_teststatus(report=rep) res = self.config.hook.pytest_report_teststatus(report=rep)
cat, letter, word = res cat, letter, word = res
self.stats.setdefault(cat, []).append(rep) self.stats.setdefault(cat, []).append(rep)
self._tests_ran = True
if not letter and not word: if not letter and not word:
# probably passed setup/teardown # probably passed setup/teardown
return return

View File

@ -317,7 +317,7 @@ class TestFunctional:
request.applymarker(pytest.mark.hello) request.applymarker(pytest.mark.hello)
def pytest_terminal_summary(terminalreporter): def pytest_terminal_summary(terminalreporter):
l = terminalreporter.stats['passed'] l = terminalreporter.stats['passed']
terminalreporter._tw.line("keyword: %s" % l[0].keywords) terminalreporter.writer.line("keyword: %s" % l[0].keywords)
""") """)
testdir.makepyfile(""" testdir.makepyfile("""
def test_func(arg): def test_func(arg):

View File

@ -699,3 +699,16 @@ def test_tbstyle_native_setup_error(testdir):
result.stdout.fnmatch_lines([ 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*'
]) ])
def test_terminal_summary(testdir):
testdir.makeconftest("""
def pytest_terminal_summary(terminalreporter):
w = terminalreporter
w.section("hello")
w.line("world")
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines("""
*==== hello ====*
world
""")