Skip to content

Commit 87423d3

Browse files
blueyednicoddemus
authored andcommitted
Keep explicit newlines with help texts
This makes a difference for e.g. pytest-xdist: Before: ``` --dist=distmode set mode for distributing tests to exec environments. each: … available environment. loadscope: … grouped by file to any available environment. (default) no: … ``` After: ``` --dist=distmode set mode for distributing tests to exec environments. each: send each test to all available environments. load: load balance by sending any pending test to any available environment. … (default) no: run tests inprocess, don't distribute. ``` This might also result in unexpected changes (hard wrapping), when line endings where used unintentionally, e.g. with: ``` help=""" some long help text """ ``` But the benefits from that are worth it, and it is easy to fix, as will be done for the internal `assertmode` option.
1 parent d05ef61 commit 87423d3

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/_pytest/config/argparsing.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,15 @@ def _format_action_invocation(self, action: argparse.Action) -> str:
509509
formatted_action_invocation = ", ".join(return_list)
510510
action._formatted_action_invocation = formatted_action_invocation # type: ignore
511511
return formatted_action_invocation
512+
513+
def _split_lines(self, text, width):
514+
"""Wrap lines after splitting on original newlines.
515+
516+
This allows to have explicit line breaks in the help text.
517+
"""
518+
import textwrap
519+
520+
lines = []
521+
for line in text.splitlines():
522+
lines.extend(textwrap.wrap(line.strip(), width))
523+
return lines

0 commit comments

Comments
 (0)