Skip to content

Commit 5a4c1b6

Browse files
authored
Use inspect.getdoc to massage fixture docstrings (#6668)
Ref: #2575
1 parent 75714ee commit 5a4c1b6

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/_pytest/python.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from collections import defaultdict
1010
from collections.abc import Sequence
1111
from functools import partial
12-
from textwrap import dedent
1312
from typing import List
1413
from typing import Optional
1514
from typing import Tuple
@@ -1247,7 +1246,7 @@ def write_fixture(fixture_def):
12471246
else:
12481247
funcargspec = argname
12491248
tw.line(funcargspec, green=True)
1250-
fixture_doc = fixture_def.func.__doc__
1249+
fixture_doc = inspect.getdoc(fixture_def.func)
12511250
if fixture_doc:
12521251
write_docstring(tw, fixture_doc)
12531252
else:
@@ -1332,7 +1331,7 @@ def _showfixtures_main(config, session):
13321331
tw.write(" -- %s" % bestrel, yellow=True)
13331332
tw.write("\n")
13341333
loc = getlocation(fixturedef.func, curdir)
1335-
doc = fixturedef.func.__doc__ or ""
1334+
doc = inspect.getdoc(fixturedef.func)
13361335
if doc:
13371336
write_docstring(tw, doc)
13381337
else:
@@ -1341,18 +1340,8 @@ def _showfixtures_main(config, session):
13411340

13421341

13431342
def write_docstring(tw, doc, indent=" "):
1344-
doc = doc.rstrip()
1345-
if "\n" in doc:
1346-
firstline, rest = doc.split("\n", 1)
1347-
else:
1348-
firstline, rest = doc, ""
1349-
1350-
if firstline.strip():
1351-
tw.line(indent + firstline.strip())
1352-
1353-
if rest:
1354-
for line in dedent(rest).split("\n"):
1355-
tw.write(indent + line + "\n")
1343+
for line in doc.split("\n"):
1344+
tw.write(indent + line + "\n")
13561345

13571346

13581347
class Function(PyobjMixin, nodes.Item):

0 commit comments

Comments
 (0)