@@ -66,14 +66,15 @@ def getgroup(
66
66
) -> "OptionGroup" :
67
67
"""Get (or create) a named option Group.
68
68
69
- :name: Name of the option group.
70
- :description: Long description for --help output.
71
- :after: Name of another group, used for ordering --help output.
69
+ :param name: Name of the option group.
70
+ :param description: Long description for --help output.
71
+ :param after: Name of another group, used for ordering --help output.
72
+ :returns: The option group.
72
73
73
74
The returned group object has an ``addoption`` method with the same
74
75
signature as :func:`parser.addoption <pytest.Parser.addoption>` but
75
76
will be shown in the respective group in the output of
76
- ``pytest. --help``.
77
+ ``pytest --help``.
77
78
"""
78
79
for group in self ._groups :
79
80
if group .name == name :
@@ -89,10 +90,11 @@ def getgroup(
89
90
def addoption (self , * opts : str , ** attrs : Any ) -> None :
90
91
"""Register a command line option.
91
92
92
- :opts: Option names, can be short or long options.
93
- :attrs: Same attributes which the ``add_argument()`` function of the
94
- `argparse library <https://docs.python.org/library/argparse.html>`_
95
- accepts.
93
+ :param opts:
94
+ Option names, can be short or long options.
95
+ :param attrs:
96
+ Same attributes as the argparse library's :py:func:`add_argument()
97
+ <argparse.ArgumentParser.add_argument>` function accepts.
96
98
97
99
After command line parsing, options are available on the pytest config
98
100
object via ``config.option.NAME`` where ``NAME`` is usually set
@@ -148,16 +150,24 @@ def parse_known_args(
148
150
args : Sequence [Union [str , "os.PathLike[str]" ]],
149
151
namespace : Optional [argparse .Namespace ] = None ,
150
152
) -> argparse .Namespace :
151
- """Parse and return a namespace object with known arguments at this point."""
153
+ """Parse the known arguments at this point.
154
+
155
+ :returns: An argparse namespace object.
156
+ """
152
157
return self .parse_known_and_unknown_args (args , namespace = namespace )[0 ]
153
158
154
159
def parse_known_and_unknown_args (
155
160
self ,
156
161
args : Sequence [Union [str , "os.PathLike[str]" ]],
157
162
namespace : Optional [argparse .Namespace ] = None ,
158
163
) -> Tuple [argparse .Namespace , List [str ]]:
159
- """Parse and return a namespace object with known arguments, and
160
- the remaining arguments unknown at this point."""
164
+ """Parse the known arguments at this point, and also return the
165
+ remaining unknown arguments.
166
+
167
+ :returns:
168
+ A tuple containing an argparse namespace object for the known
169
+ arguments, and a list of the unknown arguments.
170
+ """
161
171
optparser = self ._getparser ()
162
172
strargs = [os .fspath (x ) for x in args ]
163
173
return optparser .parse_known_args (strargs , namespace = namespace )
@@ -173,9 +183,9 @@ def addini(
173
183
) -> None :
174
184
"""Register an ini-file option.
175
185
176
- :name:
186
+ :param name:
177
187
Name of the ini-variable.
178
- :type:
188
+ :param type:
179
189
Type of the variable. Can be:
180
190
181
191
* ``string``: a string
@@ -189,7 +199,7 @@ def addini(
189
199
The ``paths`` variable type.
190
200
191
201
Defaults to ``string`` if ``None`` or not passed.
192
- :default:
202
+ :param default:
193
203
Default value if no ini-file option exists but is queried.
194
204
195
205
The value of ini-variables can be retrieved via a call to
@@ -354,24 +364,30 @@ def __init__(
354
364
self .options : List [Argument ] = []
355
365
self .parser = parser
356
366
357
- def addoption (self , * optnames : str , ** attrs : Any ) -> None :
367
+ def addoption (self , * opts : str , ** attrs : Any ) -> None :
358
368
"""Add an option to this group.
359
369
360
370
If a shortened version of a long option is specified, it will
361
371
be suppressed in the help. ``addoption('--twowords', '--two-words')``
362
372
results in help showing ``--two-words`` only, but ``--twowords`` gets
363
373
accepted **and** the automatic destination is in ``args.twowords``.
374
+
375
+ :param opts:
376
+ Option names, can be short or long options.
377
+ :param attrs:
378
+ Same attributes as the argparse library's :py:func:`add_argument()
379
+ <argparse.ArgumentParser.add_argument>` function accepts.
364
380
"""
365
- conflict = set (optnames ).intersection (
381
+ conflict = set (opts ).intersection (
366
382
name for opt in self .options for name in opt .names ()
367
383
)
368
384
if conflict :
369
385
raise ValueError ("option names %s already added" % conflict )
370
- option = Argument (* optnames , ** attrs )
386
+ option = Argument (* opts , ** attrs )
371
387
self ._addoption_instance (option , shortupper = False )
372
388
373
- def _addoption (self , * optnames : str , ** attrs : Any ) -> None :
374
- option = Argument (* optnames , ** attrs )
389
+ def _addoption (self , * opts : str , ** attrs : Any ) -> None :
390
+ option = Argument (* opts , ** attrs )
375
391
self ._addoption_instance (option , shortupper = True )
376
392
377
393
def _addoption_instance (self , option : "Argument" , shortupper : bool = False ) -> None :
0 commit comments