MCPcopy Create free account
hub / github.com/pytest-dev/pytest / Parser

Class Parser

src/_pytest/config/argparsing.py:34–200  ·  view source on GitHub ↗

Parser for command line arguments and ini-file values. :ivar extra_info: Dict of generic param -> value to display in case there's an error processing the command line arguments.

Source from the content-addressed store, hash-verified

32
33@final
34class Parser:
35 """Parser for command line arguments and ini-file values.
36
37 :ivar extra_info: Dict of generic param -> value to display in case
38 there's an error processing the command line arguments.
39 """
40
41 prog: Optional[str] = None
42
43 def __init__(
44 self,
45 usage: Optional[str] = None,
46 processopt: Optional[Callable[["Argument"], None]] = None,
47 *,
48 _ispytest: bool = False,
49 ) -> None:
50 check_ispytest(_ispytest)
51 self._anonymous = OptionGroup("custom options", parser=self, _ispytest=True)
52 self._groups: List[OptionGroup] = []
53 self._processopt = processopt
54 self._usage = usage
55 self._inidict: Dict[str, Tuple[str, Optional[str], Any]] = {}
56 self._ininames: List[str] = []
57 self.extra_info: Dict[str, Any] = {}
58
59 def processoption(self, option: "Argument") -> None:
60 if self._processopt:
61 if option.dest:
62 self._processopt(option)
63
64 def getgroup(
65 self, name: str, description: str = "", after: Optional[str] = None
66 ) -> "OptionGroup":
67 """Get (or create) a named option Group.
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.
72
73 The returned group object has an ``addoption`` method with the same
74 signature as :func:`parser.addoption <pytest.Parser.addoption>` but
75 will be shown in the respective group in the output of
76 ``pytest. --help``.
77 """
78 for group in self._groups:
79 if group.name == name:
80 return group
81 group = OptionGroup(name, description, parser=self, _ispytest=True)
82 i = 0
83 for i, grp in enumerate(self._groups):
84 if grp.name == after:
85 break
86 self._groups.insert(i + 1, group)
87 return group
88
89 def addoption(self, *opts: str, **attrs: Any) -> None:
90 """Register a command line option.
91

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected