add terminalreporter.section|line methods to print extra information.
This commit is contained in:
parent
209a0cd5b2
commit
1fc466e8ac
|
@ -142,7 +142,9 @@ Bug fixes:
|
|||
|
||||
- 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
|
||||
-----------------------------------
|
||||
|
|
|
@ -221,7 +221,7 @@ def pytest_report_teststatus(report):
|
|||
pytest_report_teststatus.firstresult = True
|
||||
|
||||
def pytest_terminal_summary(terminalreporter):
|
||||
""" add additional section in terminal summary reporting. """
|
||||
""" add additional section in terminal summary reporting. """
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# doctest hooks
|
||||
|
|
|
@ -100,7 +100,7 @@ class TerminalReporter:
|
|||
self.startdir = self.curdir = py.path.local()
|
||||
if file is None:
|
||||
file = py.std.sys.stdout
|
||||
self._tw = py.io.TerminalWriter(file)
|
||||
self._tw = self.writer = py.io.TerminalWriter(file)
|
||||
self.currentfspath = None
|
||||
self.reportchars = getreportopt(config)
|
||||
self.hasmarkup = self._tw.hasmarkup
|
||||
|
@ -148,6 +148,12 @@ class TerminalReporter:
|
|||
self.ensure_newline()
|
||||
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):
|
||||
for line in str(excrepr).split("\n"):
|
||||
self.write_line("INTERNALERROR> " + line)
|
||||
|
@ -179,6 +185,7 @@ class TerminalReporter:
|
|||
res = self.config.hook.pytest_report_teststatus(report=rep)
|
||||
cat, letter, word = res
|
||||
self.stats.setdefault(cat, []).append(rep)
|
||||
self._tests_ran = True
|
||||
if not letter and not word:
|
||||
# probably passed setup/teardown
|
||||
return
|
||||
|
|
|
@ -317,7 +317,7 @@ class TestFunctional:
|
|||
request.applymarker(pytest.mark.hello)
|
||||
def pytest_terminal_summary(terminalreporter):
|
||||
l = terminalreporter.stats['passed']
|
||||
terminalreporter._tw.line("keyword: %s" % l[0].keywords)
|
||||
terminalreporter.writer.line("keyword: %s" % l[0].keywords)
|
||||
""")
|
||||
testdir.makepyfile("""
|
||||
def test_func(arg):
|
||||
|
|
|
@ -699,3 +699,16 @@ def test_tbstyle_native_setup_error(testdir):
|
|||
result.stdout.fnmatch_lines([
|
||||
'*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
|
||||
""")
|
||||
|
|
Loading…
Reference in New Issue