From 412be414f81a02d174b535612d1f71e0c2949364 Mon Sep 17 00:00:00 2001 From: suspe Date: Fri, 11 Oct 2024 21:18:51 +0300 Subject: [PATCH] Fix ambiguous docstring of pytest.Config For full context see issue #10558 --- changelog/10558.doc.rst | 1 + src/_pytest/config/__init__.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelog/10558.doc.rst diff --git a/changelog/10558.doc.rst b/changelog/10558.doc.rst new file mode 100644 index 00000000000..d9defa5b2ff --- /dev/null +++ b/changelog/10558.doc.rst @@ -0,0 +1 @@ +Fix ambiguous docstring of `pytest.Config.getoption`. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index c53661dbeb5..6e6d935a064 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1695,13 +1695,16 @@ def _get_override_ini_value(self, name: str) -> str | None: return value def getoption(self, name: str, default=notset, skip: bool = False): - """Return command line option value. + """Return command line option value if exists + An option "exists" if the parser has been taught to expect it using parser.addoption in pytest_addoption hook. :param name: Name of the option. You may also specify the literal ``--OPT`` option instead of the "dest" option name. - :param default: Default value if no option of that name exists. + :param default: Default value if no option of that name exists (see note on option existence). + If an option exists then this parameter will be ignored even if the option's value is None. :param skip: If True, raise pytest.skip if option does not exists - or has a None value. + or has a None value. In case the option name doesn't exist, + but a default param was passed, then the default will be returned instead of a skip. """ name = self._opt2dest.get(name, name) try: