From 5a4c1b628b6b6b349618cabd8da4b52a63ec5b98 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 4 Feb 2020 03:07:53 +0100 Subject: [PATCH] Use inspect.getdoc to massage fixture docstrings (#6668) Ref: https://github.com/pytest-dev/pytest/pull/2575 --- src/_pytest/python.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 466f260f7..b960d9784 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -9,7 +9,6 @@ from collections import Counter from collections import defaultdict from collections.abc import Sequence from functools import partial -from textwrap import dedent from typing import List from typing import Optional from typing import Tuple @@ -1247,7 +1246,7 @@ def _show_fixtures_per_test(config, session): else: funcargspec = argname tw.line(funcargspec, green=True) - fixture_doc = fixture_def.func.__doc__ + fixture_doc = inspect.getdoc(fixture_def.func) if fixture_doc: write_docstring(tw, fixture_doc) else: @@ -1332,7 +1331,7 @@ def _showfixtures_main(config, session): tw.write(" -- %s" % bestrel, yellow=True) tw.write("\n") loc = getlocation(fixturedef.func, curdir) - doc = fixturedef.func.__doc__ or "" + doc = inspect.getdoc(fixturedef.func) if doc: write_docstring(tw, doc) else: @@ -1341,18 +1340,8 @@ def _showfixtures_main(config, session): def write_docstring(tw, doc, indent=" "): - doc = doc.rstrip() - if "\n" in doc: - firstline, rest = doc.split("\n", 1) - else: - firstline, rest = doc, "" - - if firstline.strip(): - tw.line(indent + firstline.strip()) - - if rest: - for line in dedent(rest).split("\n"): - tw.write(indent + line + "\n") + for line in doc.split("\n"): + tw.write(indent + line + "\n") class Function(PyobjMixin, nodes.Item):