Merge pull request #6817 from blueyed/argparsing-_split_lines-upstream

This commit is contained in:
Bruno Oliveira 2020-05-19 20:06:51 -03:00 committed by GitHub
commit 88214310af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 11 deletions

View File

@ -0,0 +1,2 @@
Explicit new-lines in help texts of command-line options are preserved, allowing plugins better control
of the help displayed to users.

View File

@ -27,11 +27,12 @@ def pytest_addoption(parser):
choices=("rewrite", "plain"), choices=("rewrite", "plain"),
default="rewrite", default="rewrite",
metavar="MODE", metavar="MODE",
help="""Control assertion debugging tools. 'plain' help=(
performs no assertion debugging. 'rewrite' "Control assertion debugging tools.\n"
(the default) rewrites assert statements in "'plain' performs no assertion debugging.\n"
test modules on import to provide assert "'rewrite' (the default) rewrites assert statements in test modules"
expression information.""", " on import to provide assert expression information."
),
) )
parser.addini( parser.addini(
"enable_assertion_pass_hook", "enable_assertion_pass_hook",

View File

@ -397,9 +397,9 @@ def pytest_addoption(parser):
"--failed-first", "--failed-first",
action="store_true", action="store_true",
dest="failedfirst", dest="failedfirst",
help="run all tests but run the last failures first. " help="run all tests, but run the last failures first.\n"
"This may re-order tests and thus lead to " "This may re-order tests and thus lead to "
"repeated fixture setup/teardown", "repeated fixture setup/teardown.",
) )
group.addoption( group.addoption(
"--nf", "--nf",

View File

@ -509,3 +509,15 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
formatted_action_invocation = ", ".join(return_list) formatted_action_invocation = ", ".join(return_list)
action._formatted_action_invocation = formatted_action_invocation # type: ignore action._formatted_action_invocation = formatted_action_invocation # type: ignore
return formatted_action_invocation return formatted_action_invocation
def _split_lines(self, text, width):
"""Wrap lines after splitting on original newlines.
This allows to have explicit line breaks in the help text.
"""
import textwrap
lines = []
for line in text.splitlines():
lines.extend(textwrap.wrap(line.strip(), width))
return lines

View File

@ -57,7 +57,7 @@ def pytest_addoption(parser):
dest="plugins", dest="plugins",
default=[], default=[],
metavar="name", metavar="name",
help="early-load given plugin module name or entry point (multi-allowed). " help="early-load given plugin module name or entry point (multi-allowed).\n"
"To avoid loading of plugins, use the `no:` prefix, e.g. " "To avoid loading of plugins, use the `no:` prefix, e.g. "
"`no:doctest`.", "`no:doctest`.",
) )

View File

@ -79,8 +79,8 @@ def pytest_addoption(parser):
dest="markexpr", dest="markexpr",
default="", default="",
metavar="MARKEXPR", metavar="MARKEXPR",
help="only run tests matching given mark expression. " help="only run tests matching given mark expression.\n"
"example: -m 'mark1 and not mark2'.", "For example: -m 'mark1 and not mark2'.",
) )
group.addoption( group.addoption(

View File

@ -19,7 +19,10 @@ def test_help(testdir):
assert result.ret == 0 assert result.ret == 0
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
""" """
*-v*verbose* -m MARKEXPR only run tests matching given mark expression.
For example: -m 'mark1 and not mark2'.
reporting:
--durations=N *
*setup.cfg* *setup.cfg*
*minversion* *minversion*
*to see*markers*pytest --markers* *to see*markers*pytest --markers*