@@ -141,24 +141,48 @@ def pytest_cmdline_main(config):
141141
142142
143143def showhelp (config ):
144+ import textwrap
145+
144146 reporter = config .pluginmanager .get_plugin ("terminalreporter" )
145147 tw = reporter ._tw
146148 tw .write (config ._parser .optparser .format_help ())
147149 tw .line ()
148- tw .line ()
149150 tw .line (
150151 "[pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg file found:"
151152 )
152153 tw .line ()
153154
154155 columns = tw .fullwidth # costly call
156+ indent_len = 24 # based on argparse's max_help_position=24
157+ indent = " " * indent_len
155158 for name in config ._parser ._ininames :
156159 help , type , default = config ._parser ._inidict [name ]
157160 if type is None :
158161 type = "string"
159- spec = "%s (%s)" % (name , type )
160- line = " %-24s %s" % (spec , help )
161- tw .line (line [:columns ])
162+ spec = "%s (%s):" % (name , type )
163+ tw .write (" %s" % spec )
164+ spec_len = len (spec )
165+ if spec_len > (indent_len - 3 ):
166+ # Display help starting at a new line.
167+ tw .line ()
168+ helplines = textwrap .wrap (
169+ help ,
170+ columns ,
171+ initial_indent = indent ,
172+ subsequent_indent = indent ,
173+ break_on_hyphens = False ,
174+ )
175+
176+ for line in helplines :
177+ tw .line (line )
178+ else :
179+ # Display help starting after the spec, following lines indented.
180+ tw .write (" " * (indent_len - spec_len - 2 ))
181+ wrapped = textwrap .wrap (help , columns - indent_len , break_on_hyphens = False )
182+
183+ tw .line (wrapped [0 ])
184+ for line in wrapped [1 :]:
185+ tw .line (indent + line )
162186
163187 tw .line ()
164188 tw .line ("environment variables:" )
0 commit comments