Skip to content

Conversation

@midoriao
Copy link

@midoriao midoriao commented Nov 5, 2025

This PR clarifies the pytest.Config.getoption docstring to make the exceptional behavior of default with skip=True explicit.

Also adds a small test verifying that behavior.

Stituation before this change

The previous docstring implied:

  • The default parameter is ignored when the option is declared.

But actual behavior is:

  • The default is not ignored even if the option is declared, when skip=True and the option has None value.

This can be reproduced by the following test case (already existing in testing/test_config.py):

def test_config_getoption_declared_option_name(self, pytester: Pytester) -> None:
	pytester.makeconftest(
		"""
		def pytest_addoption(parser):
			parser.addoption("--hello", "-X", dest="hello")
	"""
	)
	config_novalue = pytester.parseconfig()
	assert config_novalue.getoption("hello", default=1, skip=True) == 1

Rationale

The getoption() behavior involves multiple conditions (whether the option is declared or not, None or not, default, skip), which previously made the docstring easy to misinterpret. This PR avoids multiple "note that ..." caveats and keeps each parameter’s description self-contained and readable.

  • The docstring now describes the skip=True special case in plain language.
  • The misleading reference to the pytest_addoption hook was removed, since this method’s behavior is independent of how the option was added.
  • The emphasis markup of **declared** was removed.
  • Clarify the case when default=None and skip=True.

Notes

No behavior change; documentation and test addition only.
Related historical issue: #10558

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant