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
)
| 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. |