Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/_pytest/config/findpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def load_config_dict_from_file(

# '.toml' files are considered if they contain a [tool.pytest] table (toml mode)
# or [tool.pytest.ini_options] table (ini mode) for pyproject.toml,
# or [pytest] table (toml mode) for pytest.toml/.pytest.toml.
# or [pytest] table (toml mode) for pytest.toml/.pytest.toml and other custom
# TOML config files.
elif filepath.suffix == ".toml":
if sys.version_info >= (3, 11):
import tomllib
Expand Down Expand Up @@ -126,7 +127,7 @@ def load_config_dict_from_file(
return {}

# pyproject.toml uses [tool.pytest] or [tool.pytest.ini_options].
else:
elif filepath.name == "pyproject.toml":
tool_pytest = config.get("tool", {}).get("pytest", {})

# Check for toml mode config: [tool.pytest] with content outside of ini_options.
Expand Down Expand Up @@ -160,6 +161,17 @@ def make_scalar(v: object) -> str | list[str]:
for k, v in ini_config.items()
}

# Any other .toml file (custom config passed via --config-file) uses [pytest] table.
else:
if "pytest" in config:
# TOML mode - preserve native TOML types.
return {
k: ConfigValue(v, origin="file", mode="toml")
for k, v in config["pytest"].items()
}
# Custom TOML files are always the source of configuration, even if empty.
return {}

return None


Expand Down
Loading