introduce a new pytest_report_header(hook) hook to add additional test-run relevant information to the header of a test report.
--HG-- branch : trunk
This commit is contained in:
@@ -109,6 +109,9 @@ def pytest_sessionfinish(session, exitstatus):
|
||||
# hooks for influencing reporting (invoked from pytest_terminal)
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
def pytest_report_header(config):
|
||||
""" return a string to be displayed as header info for terminal reporting."""
|
||||
|
||||
def pytest_report_teststatus(report):
|
||||
""" return result-category, shortletter and verbose word for reporting."""
|
||||
pytest_report_teststatus.firstresult = True
|
||||
|
||||
@@ -10,9 +10,19 @@ def pytest_addoption(parser):
|
||||
group._addoption('-p', action="append", dest="plugins", default = [],
|
||||
metavar="name",
|
||||
help="early-load given plugin (multi-allowed).")
|
||||
group.addoption('--traceconfig',
|
||||
action="store_true", dest="traceconfig", default=False,
|
||||
help="trace considerations of conftest.py files."),
|
||||
group._addoption('--nomagic',
|
||||
action="store_true", dest="nomagic", default=False,
|
||||
help="don't reinterpret asserts, no traceback cutting. ")
|
||||
group.addoption('--debug',
|
||||
action="store_true", dest="debug", default=False,
|
||||
help="generate and show internal debugging information.")
|
||||
group.addoption("--help-config", action="store_true", dest="helpconfig",
|
||||
help="show available conftest.py and ENV-variable names.")
|
||||
|
||||
|
||||
def pytest_configure(__multicall__, config):
|
||||
if config.option.version:
|
||||
p = py.path.local(py.__file__).dirpath()
|
||||
@@ -65,6 +75,19 @@ conftest_options = (
|
||||
('rsyncdirs', 'to-be-rsynced directories for dist-testing'),
|
||||
)
|
||||
|
||||
def pytest_report_header(config):
|
||||
lines = []
|
||||
if config.option.debug or config.option.traceconfig:
|
||||
lines.append("using py lib: %s" % (py.path.local(py.__file__).dirpath()))
|
||||
if config.option.traceconfig:
|
||||
lines.append("active plugins:")
|
||||
plugins = []
|
||||
items = config.pluginmanager._name2plugin.items()
|
||||
for name, plugin in items:
|
||||
lines.append(" %-20s: %s" %(name, repr(plugin)))
|
||||
return lines
|
||||
|
||||
|
||||
# =====================================================
|
||||
# validate plugin syntax and hooks
|
||||
# =====================================================
|
||||
|
||||
@@ -24,17 +24,6 @@ def pytest_addoption(parser):
|
||||
action="store_true", dest="fulltrace", default=False,
|
||||
help="don't cut any tracebacks (default is to cut).")
|
||||
|
||||
group = parser.getgroup("debugconfig")
|
||||
group.addoption('--traceconfig',
|
||||
action="store_true", dest="traceconfig", default=False,
|
||||
help="trace considerations of conftest.py files."),
|
||||
group._addoption('--nomagic',
|
||||
action="store_true", dest="nomagic", default=False,
|
||||
help="don't reinterpret asserts, no traceback cutting. ")
|
||||
group.addoption('--debug',
|
||||
action="store_true", dest="debug", default=False,
|
||||
help="generate and show internal debugging information.")
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
if config.option.collectonly:
|
||||
@@ -260,19 +249,10 @@ class TerminalReporter:
|
||||
if self.config.option.verbose or self.config.option.debug or getattr(self.config.option, 'pastebin', None):
|
||||
msg += " -- " + str(sys.executable)
|
||||
self.write_line(msg)
|
||||
|
||||
if self.config.option.debug or self.config.option.traceconfig:
|
||||
self.write_line("using py lib: %s" % (py.path.local(py.__file__).dirpath()))
|
||||
if self.config.option.traceconfig:
|
||||
self.write_line("active plugins:")
|
||||
plugins = []
|
||||
items = self.config.pluginmanager._name2plugin.items()
|
||||
for name, plugin in items:
|
||||
repr_plugin = repr(plugin)
|
||||
fullwidth = getattr(self._tw, 'fullwidth', 65000)
|
||||
if len(repr_plugin)+26 > fullwidth:
|
||||
repr_plugin = repr_plugin[:(fullwidth-30)] + '...'
|
||||
self.write_line(" %-20s: %s" %(name, repr_plugin))
|
||||
lines = self.config.hook.pytest_report_header(config=self.config)
|
||||
lines.reverse()
|
||||
for line in flatten(lines):
|
||||
self.write_line(line)
|
||||
for i, testarg in enumerate(self.config.args):
|
||||
self.write_line("test object %d: %s" %(i+1, testarg))
|
||||
|
||||
@@ -463,3 +443,10 @@ def repr_pythonversion(v=None):
|
||||
except (TypeError, ValueError):
|
||||
return str(v)
|
||||
|
||||
def flatten(l):
|
||||
for x in l:
|
||||
if isinstance(x, (list, tuple)):
|
||||
for y in flatten(x):
|
||||
yield y
|
||||
else:
|
||||
yield x
|
||||
|
||||
Reference in New Issue
Block a user