MCPcopy
hub / github.com/pytest-dev/pytest / getgroup

Method getgroup

src/_pytest/config/argparsing.py:74–103  ·  view source on GitHub ↗

Get (or create) a named option Group. :param name: Name of the option group. :param description: Long description for --help output. :param after: Name of another group, used for ordering --help output. :returns: The option group. The returned group object h

(
        self, name: str, description: str = "", after: str | None = None
    )

Source from the content-addressed store, hash-verified

72 self._processopt(option)
73
74 def getgroup(
75 self, name: str, description: str = "", after: str | None = None
76 ) -> OptionGroup:
77 """Get (or create) a named option Group.
78
79 :param name: Name of the option group.
80 :param description: Long description for --help output.
81 :param after: Name of another group, used for ordering --help output.
82 :returns: The option group.
83
84 The returned group object has an ``addoption`` method with the same
85 signature as :func:`parser.addoption <pytest.Parser.addoption>` but
86 will be shown in the respective group in the output of
87 ``pytest --help``.
88 """
89 for group in self._groups:
90 if group.name == name:
91 return group
92
93 arggroup = self.optparser.add_argument_group(description or name)
94 group = OptionGroup(arggroup, name, self, _ispytest=True)
95 i = 0
96 for i, grp in enumerate(self._groups):
97 if grp.name == after:
98 break
99 self._groups.insert(i + 1, group)
100 # argparse doesn't provide a way to control `--help` order, so must
101 # access its internals ☹.
102 self.optparser._action_groups.insert(i + 1, self.optparser._action_groups.pop())
103 return group
104
105 def addoption(self, *opts: str, **attrs: Any) -> None:
106 """Register a command line option.

Callers 15

pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80
pytest_addoptionFunction · 0.80

Calls 3

OptionGroupClass · 0.85
insertMethod · 0.80
popMethod · 0.80

Tested by 8

pytest_addoptionFunction · 0.64
test_getgroup_simpleMethod · 0.64
test_group_orderingMethod · 0.64
test_parser_addoptionMethod · 0.64
test_drop_short_help1Method · 0.64