Skip to content

pytest.toml: treat headerless top-level keys as pytest config#14648

Closed
MD-Mushfiqur123 wants to merge 2 commits into
pytest-dev:mainfrom
MD-Mushfiqur123:fix/headerless-pytest-toml-14638
Closed

pytest.toml: treat headerless top-level keys as pytest config#14648
MD-Mushfiqur123 wants to merge 2 commits into
pytest-dev:mainfrom
MD-Mushfiqur123:fix/headerless-pytest-toml-14638

Conversation

@MD-Mushfiqur123

Copy link
Copy Markdown

Closes #14638

Problem

When a pytest.toml or .pytest.toml file contains top-level keys without a [pytest] section header, those keys are silently ignored. This is surprising because:

  • TOML sections are optional (unlike INI files)
  • The filename itself already identifies the file as pytest configuration

Solution

Treat top-level non-table keys in pytest.toml/.pytest.toml as pytest configuration, as if they were written under [pytest]. If a [pytest] section is also present, its values are merged on top (taking precedence).

For example, this now works:

minversion = "9.0"
addopts = ["-v"]

Testing

  • All existing TOML config tests pass (24 tests)
  • Added test_headerless_pytest_toml for both pytest.toml and .pytest.toml
  • Verified manually that the config values are properly parsed and applied

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

Ai slop when there's a correct pr existing

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.toml without section header leads to silently ignored options

2 participants