Skip to content

fix: return default value in Config.getoption when option is None#14440

Closed
zons-zhaozhy wants to merge 1 commit intopytest-dev:mainfrom
zons-zhaozhy:fix/getoption-default
Closed

fix: return default value in Config.getoption when option is None#14440
zons-zhaozhy wants to merge 1 commit intopytest-dev:mainfrom
zons-zhaozhy:fix/getoption-default

Conversation

@zons-zhaozhy
Copy link
Copy Markdown

The default argument to Config.getoption() was never returned
when the option value was None. The method returned None directly
without checking the default parameter.

Fix: when val is None, check default first before returning None.

Fixes #10558

…10558)

The default parameter was only checked inside the except AttributeError
block. When an option was declared but had a None value (and skip=False),
the method returned None directly without ever consulting the default
parameter.

Fix by checking for default when val is None before returning None.
Also update the docstring to reflect that default applies when the
option's value is None, not just when undeclared.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest.Config.getoption default argument not working as expected

3 participants