Merge pull request #7064 from blueyed/fix-_printcollecteditems-doc-upstream
Fix/improve printing of docs for collected items
This commit is contained in:
commit
d7d627b1e8
|
@ -5,6 +5,7 @@ This is a good source for looking at the various reporting hooks.
|
|||
import argparse
|
||||
import collections
|
||||
import datetime
|
||||
import inspect
|
||||
import platform
|
||||
import sys
|
||||
import time
|
||||
|
@ -707,9 +708,14 @@ class TerminalReporter:
|
|||
indent = (len(stack) - 1) * " "
|
||||
self._tw.line("{}{}".format(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("{}{}".format(indent + " ", line.strip()))
|
||||
try:
|
||||
obj = col.obj # type: ignore
|
||||
except AttributeError:
|
||||
continue
|
||||
doc = inspect.getdoc(obj)
|
||||
if doc:
|
||||
for line in doc.splitlines():
|
||||
self._tw.line("{}{}".format(indent + " ", line))
|
||||
|
||||
@pytest.hookimpl(hookwrapper=True)
|
||||
def pytest_sessionfinish(self, session: Session, exitstatus: ExitCode):
|
||||
|
|
|
@ -353,17 +353,33 @@ class TestCollectonly:
|
|||
result = testdir.runpytest("--collect-only", "-rs")
|
||||
result.stdout.fnmatch_lines(["*ERROR collecting*"])
|
||||
|
||||
def test_collectonly_display_test_description(self, testdir):
|
||||
def test_collectonly_displays_test_description(
|
||||
self, testdir: Testdir, dummy_yaml_custom_test
|
||||
) -> None:
|
||||
"""Used dummy_yaml_custom_test for an Item without ``obj``."""
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
def test_with_description():
|
||||
\""" This test has a description.
|
||||
\"""
|
||||
assert True
|
||||
"""
|
||||
''' This test has a description.
|
||||
|
||||
more1.
|
||||
more2.'''
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("--collect-only", "--verbose")
|
||||
result.stdout.fnmatch_lines([" This test has a description."])
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"<YamlFile test1.yaml>",
|
||||
" <YamlItem test1.yaml>",
|
||||
"<Module test_collectonly_displays_test_description.py>",
|
||||
" <Function test_with_description>",
|
||||
" This test has a description.",
|
||||
" ",
|
||||
" more1.",
|
||||
" more2.",
|
||||
],
|
||||
consecutive=True,
|
||||
)
|
||||
|
||||
def test_collectonly_failed_module(self, testdir):
|
||||
testdir.makepyfile("""raise ValueError(0)""")
|
||||
|
|
Loading…
Reference in New Issue