Return command line option value. :param name: Name of the option. You may also specify the literal ``--OPT`` option instead of the "dest" option name. :param default: Fallback value if no option of that name is **declared** via :hook:`pytest_addoption`. Note
(self, name: str, default: Any = NOTSET, skip: bool = False)
| 1921 | return values |
| 1922 | |
| 1923 | def getoption(self, name: str, default: Any = NOTSET, skip: bool = False): |
| 1924 | class="st">"""Return command line option value. |
| 1925 | |
| 1926 | :param name: Name of the option. You may also specify |
| 1927 | the literal ``--OPT`` option instead of the class="st">"dest" option name. |
| 1928 | :param default: Fallback value if no option of that name is **declared** via :hook:`pytest_addoption`. |
| 1929 | Note this parameter will be ignored when the option is **declared** even if the option&class="cm">#x27;s value is ``None``. |
| 1930 | :param skip: If ``True``, raise :func:`pytest.skip` if option is undeclared or has a ``None`` value. |
| 1931 | Note that even if ``True``, if a default was specified it will be returned instead of a skip. |
| 1932 | class="st">""" |
| 1933 | name = self._parser._opt2dest.get(name, name) |
| 1934 | try: |
| 1935 | val = getattr(self.option, name) |
| 1936 | if val is None and skip: |
| 1937 | raise AttributeError(name) |
| 1938 | return val |
| 1939 | except AttributeError as e: |
| 1940 | if default is not NOTSET: |
| 1941 | return default |
| 1942 | if skip: |
| 1943 | import pytest |
| 1944 | |
| 1945 | pytest.skip(fclass="st">"no {name!r} option found") |
| 1946 | raise ValueError(fclass="st">"no option named {name!r}") from e |
| 1947 | |
| 1948 | def getvalue(self, name: str, path=None): |
| 1949 | class="st">""class="st">"Deprecated, use getoption() instead."class="st">"" |