Skip to content

Commit c0dc982

Browse files
committed
enable the accommodation of multi-line docstring with --fixtures-per-test option
1 parent 95e944f commit c0dc982

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

src/_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ def write_fixture(fixture_def: fixtures.FixtureDef[object]) -> None:
14331433
tw.line(funcargspec, green=True)
14341434
fixture_doc = inspect.getdoc(fixture_def.func)
14351435
if fixture_doc:
1436-
write_docstring(tw, fixture_doc.split("\n")[0])
1436+
write_docstring(tw, fixture_doc.split("\n\n")[0] if verbose<=0 else fixture_doc)
14371437
else:
14381438
tw.line(" no docstring available", red=True)
14391439

testing/python/show_fixtures_per_test.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_arg1(arg1):
3030
"*fixtures used by test_arg1*",
3131
"*(test_fixtures_in_module.py:9)*",
3232
"arg1 -- test_fixtures_in_module.py:6",
33+
" arg1 docstring"
3334
]
3435
)
3536
result.stdout.no_fnmatch_line("*_arg0*")
@@ -179,3 +180,73 @@ def foo():
179180
assert result.ret == 0
180181

181182
result.stdout.fnmatch_lines(["*collected 2 items*"])
183+
184+
def test_multiline_docstring_in_module(pytester: Pytester) -> None:
185+
p = pytester.makepyfile(
186+
'''
187+
import pytest
188+
@pytest.fixture
189+
def arg1():
190+
"""Docstring content that spans across multiple lines,
191+
through second line,
192+
and through third line.
193+
194+
Docstring content that extends into a second paragraph.
195+
196+
Docstring content that extends into a third paragraph.
197+
"""
198+
def test_arg1(arg1):
199+
pass
200+
'''
201+
)
202+
203+
result = pytester.runpytest("--fixtures-per-test", p)
204+
assert result.ret == 0
205+
206+
result.stdout.fnmatch_lines(
207+
[
208+
"*fixtures used by test_arg1*",
209+
"*(test_multiline_docstring_in_module.py:13)*",
210+
"arg1 -- test_multiline_docstring_in_module.py:3",
211+
" Docstring content that spans across multiple lines,",
212+
" through second line,",
213+
" and through third line."
214+
]
215+
)
216+
217+
def test_verbose_include_multiline_docstring(pytester: Pytester) -> None:
218+
p = pytester.makepyfile(
219+
'''
220+
import pytest
221+
@pytest.fixture
222+
def arg1():
223+
"""Docstring content that spans across multiple lines,
224+
through second line,
225+
and through third line.
226+
227+
Docstring content that extends into a second paragraph.
228+
229+
Docstring content that extends into a third paragraph.
230+
"""
231+
def test_arg1(arg1):
232+
pass
233+
'''
234+
)
235+
236+
result = pytester.runpytest("--fixtures-per-test", "-v", p)
237+
assert result.ret == 0
238+
239+
result.stdout.fnmatch_lines(
240+
[
241+
"*fixtures used by test_arg1*",
242+
"*(test_verbose_include_multiline_docstring.py:13)*",
243+
"arg1 -- test_verbose_include_multiline_docstring.py:3",
244+
" Docstring content that spans across multiple lines,",
245+
" through second line,",
246+
" and through third line.",
247+
" ",
248+
" Docstring content that extends into a second paragraph.",
249+
" ",
250+
" Docstring content that extends into a third paragraph."
251+
]
252+
)

0 commit comments

Comments
 (0)