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 argparse
 | 
				
			||||||
import collections
 | 
					import collections
 | 
				
			||||||
import datetime
 | 
					import datetime
 | 
				
			||||||
 | 
					import inspect
 | 
				
			||||||
import platform
 | 
					import platform
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
| 
						 | 
					@ -707,9 +708,14 @@ class TerminalReporter:
 | 
				
			||||||
                indent = (len(stack) - 1) * "  "
 | 
					                indent = (len(stack) - 1) * "  "
 | 
				
			||||||
                self._tw.line("{}{}".format(indent, col))
 | 
					                self._tw.line("{}{}".format(indent, col))
 | 
				
			||||||
                if self.config.option.verbose >= 1:
 | 
					                if self.config.option.verbose >= 1:
 | 
				
			||||||
                    if hasattr(col, "_obj") and col._obj.__doc__:
 | 
					                    try:
 | 
				
			||||||
                        for line in col._obj.__doc__.strip().splitlines():
 | 
					                        obj = col.obj  # type: ignore
 | 
				
			||||||
                            self._tw.line("{}{}".format(indent + "  ", line.strip()))
 | 
					                    except AttributeError:
 | 
				
			||||||
 | 
					                        continue
 | 
				
			||||||
 | 
					                    doc = inspect.getdoc(obj)
 | 
				
			||||||
 | 
					                    if doc:
 | 
				
			||||||
 | 
					                        for line in doc.splitlines():
 | 
				
			||||||
 | 
					                            self._tw.line("{}{}".format(indent + "  ", line))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @pytest.hookimpl(hookwrapper=True)
 | 
					    @pytest.hookimpl(hookwrapper=True)
 | 
				
			||||||
    def pytest_sessionfinish(self, session: Session, exitstatus: ExitCode):
 | 
					    def pytest_sessionfinish(self, session: Session, exitstatus: ExitCode):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -353,17 +353,33 @@ class TestCollectonly:
 | 
				
			||||||
        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):
 | 
					    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(
 | 
					        testdir.makepyfile(
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
            def test_with_description():
 | 
					            def test_with_description():
 | 
				
			||||||
                \""" This test has a description.
 | 
					                '''  This test has a description.
 | 
				
			||||||
                \"""
 | 
					
 | 
				
			||||||
                assert True
 | 
					                  more1.
 | 
				
			||||||
 | 
					                    more2.'''
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        result = testdir.runpytest("--collect-only", "--verbose")
 | 
					        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):
 | 
					    def test_collectonly_failed_module(self, testdir):
 | 
				
			||||||
        testdir.makepyfile("""raise ValueError(0)""")
 | 
					        testdir.makepyfile("""raise ValueError(0)""")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue