Skip to content

Commit 1a9979a

Browse files
authored
Merge pull request #4582 from jeffreyrack/4371-display-test-descriptions
4371: Update --collect-only to display test descriptions when ran in verbose
2 parents 134ace9 + 1eef53b commit 1a9979a

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

changelog/4371.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updated the ``--collect-only`` option to display test descriptions when ran using ``--verbose``.

src/_pytest/terminal.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ def _printcollecteditems(self, items):
611611
continue
612612
indent = (len(stack) - 1) * " "
613613
self._tw.line("%s%s" % (indent, col))
614+
if self.config.option.verbose >= 1:
615+
if hasattr(col, "_obj") and col._obj.__doc__:
616+
for line in col._obj.__doc__.strip().splitlines():
617+
self._tw.line("%s%s" % (indent + " ", line.strip()))
614618

615619
@pytest.hookimpl(hookwrapper=True)
616620
def pytest_sessionfinish(self, exitstatus):

testing/test_terminal.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ def test_collectonly_skipped_module(self, testdir):
276276
result = testdir.runpytest("--collect-only", "-rs")
277277
result.stdout.fnmatch_lines(["*ERROR collecting*"])
278278

279+
def test_collectonly_display_test_description(self, testdir):
280+
testdir.makepyfile(
281+
"""
282+
def test_with_description():
283+
\""" This test has a description.
284+
\"""
285+
assert True
286+
"""
287+
)
288+
result = testdir.runpytest("--collect-only", "--verbose")
289+
result.stdout.fnmatch_lines([" This test has a description."])
290+
279291
def test_collectonly_failed_module(self, testdir):
280292
testdir.makepyfile("""raise ValueError(0)""")
281293
result = testdir.runpytest("--collect-only")

0 commit comments

Comments
 (0)