diff options
author | Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> | 2016-10-21 01:36:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-21 01:36:24 +0200 |
commit | 82fb63ca2d3c8b85d8a13038a16bd104cff1ea6e (patch) | |
tree | ce602e4ea430c30b23282a8c5466d89dfb57761c | |
parent | 5cbfefbba0e941f2871ccd65a1cf91b1dba1aea4 (diff) | |
parent | 620b384b69ffaf0e98af015a721f385ceb13093c (diff) | |
download | pytest-82fb63ca2d3c8b85d8a13038a16bd104cff1ea6e.tar.gz |
Merge pull request #2019 from nicoddemus/fix-metavar-pair-help
Fix cmdline help message for custom options with two or more metavars
-rw-r--r-- | CHANGELOG.rst | 5 | ||||
-rw-r--r-- | _pytest/config.py | 2 | ||||
-rw-r--r-- | testing/test_parseopt.py | 14 |
3 files changed, 19 insertions, 2 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 237ea478f..2fb15aa11 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,9 @@ * Import errors when collecting test modules now display the full traceback (`#1976`_). Thanks `@cwitty`_ for the report and `@nicoddemus`_ for the PR. +* Fix confusing command-line help message for custom options with two or more `metavar` properties (`#2004`_). + Thanks `@okulynyak`_ and `@davehunt`_ for the report and `@nicoddemus`_ for the PR. + * When loading plugins, import errors which contain non-ascii messages are now properly handled in Python 2 (`#1998`_). Thanks `@nicoddemus`_ for the PR. @@ -13,9 +16,11 @@ .. _@cwitty: https://github.com/cwitty +.. _@okulynyak: https://github.com/okulynyak .. _#1976: https://github.com/pytest-dev/pytest/issues/1976 .. _#1998: https://github.com/pytest-dev/pytest/issues/1998 +.. _#2004: https://github.com/pytest-dev/pytest/issues/2004 diff --git a/_pytest/config.py b/_pytest/config.py index a169a68a2..5df198e21 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -793,7 +793,7 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter): if len(option) == 2 or option[2] == ' ': return_list.append(option) if option[2:] == short_long.get(option.replace('-', '')): - return_list.append(option.replace(' ', '=')) + return_list.append(option.replace(' ', '=', 1)) action._formatted_action_invocation = ', '.join(return_list) return action._formatted_action_invocation diff --git a/testing/test_parseopt.py b/testing/test_parseopt.py index cc9aa23cd..fc9ded488 100644 --- a/testing/test_parseopt.py +++ b/testing/test_parseopt.py @@ -248,7 +248,19 @@ class TestParser: help="show help message and configuration info") parser.parse(['-h']) help = parser.optparser.format_help() - assert '-doit, --func-args foo' in help + assert '-doit, --func-args foo' in help + + def test_multiple_metavar_help(self, parser): + """ + Help text for options with a metavar tuple should display help + in the form "--preferences=value1 value2 value3" (#2004). + """ + group = parser.getgroup("general") + group.addoption('--preferences', metavar=('value1', 'value2', 'value3'), nargs=3) + group._addoption("-h", "--help", action="store_true", dest="help") + parser.parse(['-h']) + help = parser.optparser.format_help() + assert '--preferences=value1 value2 value3' in help def test_argcomplete(testdir, monkeypatch): |