Merge pull request #4582 from jeffreyrack/4371-display-test-descriptions

4371: Update --collect-only to display test descriptions when ran in verbose
This commit is contained in:
Bruno Oliveira 2018-12-30 13:56:30 -02:00 committed by GitHub
commit 1a9979a803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
indent = (len(stack) - 1) * " "
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)
def pytest_sessionfinish(self, exitstatus):

View File

@ -276,6 +276,18 @@ class TestCollectonly(object):
result = testdir.runpytest("--collect-only", "-rs")
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):
testdir.makepyfile("""raise ValueError(0)""")
result = testdir.runpytest("--collect-only")