Merge pull request #2623 from nicoddemus/post-collection-report-hook
Introduce new pytest_report_collectionfinish hook
This commit is contained in:
commit
e97fd5ec55
|
@ -337,7 +337,10 @@ def pytest_assertrepr_compare(config, op, left, right):
|
|||
|
||||
|
||||
def pytest_report_header(config, startdir):
|
||||
""" return a string to be displayed as header info for terminal reporting.
|
||||
""" return a string or list of strings to be displayed as header info for terminal reporting.
|
||||
|
||||
:param config: the pytest config object.
|
||||
:param startdir: py.path object with the starting dir
|
||||
|
||||
.. note::
|
||||
|
||||
|
@ -347,6 +350,17 @@ def pytest_report_header(config, startdir):
|
|||
"""
|
||||
|
||||
|
||||
def pytest_report_collectionfinish(config, startdir, items):
|
||||
""" return a string or list of strings to be displayed after collection has finished successfully.
|
||||
|
||||
This strings will be displayed after the standard "collected X items" message.
|
||||
|
||||
:param config: the pytest config object.
|
||||
:param startdir: py.path object with the starting dir
|
||||
:param items: list of pytest items that are going to be executed; this list should not be modified.
|
||||
"""
|
||||
|
||||
|
||||
@hookspec(firstresult=True)
|
||||
def pytest_report_teststatus(report):
|
||||
""" return result-category, shortletter and verbose word for reporting.
|
||||
|
|
|
@ -323,6 +323,9 @@ class TerminalReporter:
|
|||
self.write_line(msg)
|
||||
lines = self.config.hook.pytest_report_header(
|
||||
config=self.config, startdir=self.startdir)
|
||||
self._write_report_lines_from_hooks(lines)
|
||||
|
||||
def _write_report_lines_from_hooks(self, lines):
|
||||
lines.reverse()
|
||||
for line in flatten(lines):
|
||||
self.write_line(line)
|
||||
|
@ -349,10 +352,9 @@ class TerminalReporter:
|
|||
rep.toterminal(self._tw)
|
||||
return 1
|
||||
return 0
|
||||
if not self.showheader:
|
||||
return
|
||||
# for i, testarg in enumerate(self.config.args):
|
||||
# self.write_line("test path %d: %s" %(i+1, testarg))
|
||||
lines = self.config.hook.pytest_report_collectionfinish(
|
||||
config=self.config, startdir=self.startdir, items=session.items)
|
||||
self._write_report_lines_from_hooks(lines)
|
||||
|
||||
def _printcollecteditems(self, items):
|
||||
# to print out items and their parent collectors
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
New ``pytest_report_collectionfinish`` hook which allows plugins to add messages to the terminal reporting after
|
||||
collection has been finished successfully.
|
|
@ -644,6 +644,7 @@ Session related reporting hooks:
|
|||
.. autofunction:: pytest_collectreport
|
||||
.. autofunction:: pytest_deselected
|
||||
.. autofunction:: pytest_report_header
|
||||
.. autofunction:: pytest_report_collectionfinish
|
||||
.. autofunction:: pytest_report_teststatus
|
||||
.. autofunction:: pytest_terminal_summary
|
||||
.. autofunction:: pytest_fixture_setup
|
||||
|
|
|
@ -544,6 +544,23 @@ class TestTerminalFunctional(object):
|
|||
assert "===" not in s
|
||||
assert "passed" not in s
|
||||
|
||||
def test_report_collectionfinish_hook(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
def pytest_report_collectionfinish(config, startdir, items):
|
||||
return ['hello from hook: {0} items'.format(len(items))]
|
||||
""")
|
||||
testdir.makepyfile("""
|
||||
import pytest
|
||||
@pytest.mark.parametrize('i', range(3))
|
||||
def test(i):
|
||||
pass
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines([
|
||||
"collected 3 items",
|
||||
"hello from hook: 3 items",
|
||||
])
|
||||
|
||||
|
||||
def test_fail_extra_reporting(testdir):
|
||||
testdir.makepyfile("def test_this(): assert 0")
|
||||
|
|
Loading…
Reference in New Issue