Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ Nico Vidal
Nikesh Chavhan
Nikolay Kondratyev
Nipunn Koorapati
niukanen1
Oleg Pidsadnyi
Oleg Sushchenko
Oleksandr Zavertniev
Expand Down
1 change: 1 addition & 0 deletions changelog/15021.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserved blank lines between paragraphs in command-line option help text.
2 changes: 1 addition & 1 deletion src/_pytest/config/argparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def _split_lines(self, text: str, width: int) -> list[str]:
"""
lines = []
for line in text.splitlines():
lines.extend(textwrap.wrap(line.strip(), width))
lines.extend(textwrap.wrap(line.strip(), width) or [""])
return lines


Expand Down
25 changes: 25 additions & 0 deletions testing/test_parseopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,31 @@ def test_drop_short_help0(self, parser: parseopt.Parser) -> None:
help = parser.optparser.format_help()
assert "--func-args, --doit foo" in help

def test_help_preserves_blank_lines(self, parser: parseopt.Parser) -> None:
parser.addoption(
"--paragraph-help",
action="store_true",
help="first paragraph\n\nsecond paragraph",
)

lines = parser.optparser.format_help().splitlines()
first_line = next(
i for i, line in enumerate(lines) if "first paragraph" in line
)

assert lines[first_line + 1].strip() == ""
assert lines[first_line + 2].strip() == "second paragraph"

def test_help_line_wrapping_with_blank_lines(self) -> None:
formatter = parseopt.DropShorterLongHelpFormatter("prog")

assert formatter._split_lines("first paragraph\n\nsecond paragraph", 80) == [
"first paragraph",
"",
"second paragraph",
]
assert formatter._split_lines("one two three", 7) == ["one two", "three"]

# testing would be more helpful with all help generated
def test_drop_short_help1(self, parser: parseopt.Parser) -> None:
group = parser.getgroup("general")
Expand Down
Loading