Update --collect-only to display test descriptions when ran in verbose mode.

This commit is contained in:
Jeffrey Rackauckas 2018-12-29 22:46:46 -08:00
parent 134ace98d9
commit 1eef53b6fe
3 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1 @@
Updated the ``--collect-only`` option to display test descriptions when ran using ``--verbose``.

View File

@ -611,6 +611,10 @@ class TerminalReporter(object):
continue continue
indent = (len(stack) - 1) * " " indent = (len(stack) - 1) * " "
self._tw.line("%s%s" % (indent, col)) self._tw.line("%s%s" % (indent, col))
if self.config.option.verbose >= 1:
if hasattr(col, "_obj") and col._obj.__doc__:
for line in col._obj.__doc__.strip().splitlines():
self._tw.line("%s%s" % (indent + " ", line.strip()))
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_sessionfinish(self, exitstatus): def pytest_sessionfinish(self, exitstatus):

View File

@ -276,6 +276,18 @@ class TestCollectonly(object):
result = testdir.runpytest("--collect-only", "-rs") result = testdir.runpytest("--collect-only", "-rs")
result.stdout.fnmatch_lines(["*ERROR collecting*"]) result.stdout.fnmatch_lines(["*ERROR collecting*"])
def test_collectonly_display_test_description(self, testdir):
testdir.makepyfile(
"""
def test_with_description():
\""" This test has a description.
\"""
assert True
"""
)
result = testdir.runpytest("--collect-only", "--verbose")
result.stdout.fnmatch_lines([" This test has a description."])
def test_collectonly_failed_module(self, testdir): def test_collectonly_failed_module(self, testdir):
testdir.makepyfile("""raise ValueError(0)""") testdir.makepyfile("""raise ValueError(0)""")
result = testdir.runpytest("--collect-only") result = testdir.runpytest("--collect-only")