Skip to content

Commit 620b384

Browse files
committed
Fix cmdline help message for custom options with two or more metavars
Fix #2004
1 parent 5cbfefb commit 620b384

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66
* Import errors when collecting test modules now display the full traceback (`#1976`_).
77
Thanks `@cwitty`_ for the report and `@nicoddemus`_ for the PR.
88

9+
* Fix confusing command-line help message for custom options with two or more `metavar` properties (`#2004`_).
10+
Thanks `@okulynyak`_ and `@davehunt`_ for the report and `@nicoddemus`_ for the PR.
11+
912
* When loading plugins, import errors which contain non-ascii messages are now properly handled in Python 2 (`#1998`_).
1013
Thanks `@nicoddemus`_ for the PR.
1114

1215
*
1316

1417

1518
.. _@cwitty: https://github.com/cwitty
19+
.. _@okulynyak: https://github.com/okulynyak
1620

1721
.. _#1976: https://github.com/pytest-dev/pytest/issues/1976
1822
.. _#1998: https://github.com/pytest-dev/pytest/issues/1998
23+
.. _#2004: https://github.com/pytest-dev/pytest/issues/2004
1924

2025

2126

_pytest/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ def _format_action_invocation(self, action):
793793
if len(option) == 2 or option[2] == ' ':
794794
return_list.append(option)
795795
if option[2:] == short_long.get(option.replace('-', '')):
796-
return_list.append(option.replace(' ', '='))
796+
return_list.append(option.replace(' ', '=', 1))
797797
action._formatted_action_invocation = ', '.join(return_list)
798798
return action._formatted_action_invocation
799799

testing/test_parseopt.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,19 @@ def test_drop_short_help1(self, parser, capsys):
248248
help="show help message and configuration info")
249249
parser.parse(['-h'])
250250
help = parser.optparser.format_help()
251-
assert '-doit, --func-args foo' in help
251+
assert '-doit, --func-args foo' in help
252+
253+
def test_multiple_metavar_help(self, parser):
254+
"""
255+
Help text for options with a metavar tuple should display help
256+
in the form "--preferences=value1 value2 value3" (#2004).
257+
"""
258+
group = parser.getgroup("general")
259+
group.addoption('--preferences', metavar=('value1', 'value2', 'value3'), nargs=3)
260+
group._addoption("-h", "--help", action="store_true", dest="help")
261+
parser.parse(['-h'])
262+
help = parser.optparser.format_help()
263+
assert '--preferences=value1 value2 value3' in help
252264

253265

254266
def test_argcomplete(testdir, monkeypatch):

0 commit comments

Comments
 (0)