Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog.d/+empty-native-section.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Honor an empty native TOML environment section over INI `env` settings.
5 changes: 2 additions & 3 deletions src/pytest_env/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,8 @@ def _load_values(early_config: pytest.Config) -> Iterator[Entry]:
"""Load env entries from config, preferring TOML over INI."""
if toml_config := _find_toml_config(early_config):
_, entries, _ = _load_toml_config(toml_config)
if entries:
yield from entries
return
yield from entries
return

for line in early_config.getini("env"):
# INI lines e.g. D:R:NAME=VAL has two flags (R and D), NAME key, and VAL value
Expand Down
30 changes: 28 additions & 2 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,33 @@ def test_env_via_pytest(
".pytest.toml",
id="hidden pytest toml native over ini",
),
pytest.param(
{},
"[tool.pytest_env]\n",
"",
"[pytest]\nenv = FROM_INI=unexpected",
{"FROM_INI": None},
None,
id="empty pyproject native over ini",
),
pytest.param(
{},
"",
"[pytest_env]\n",
"[pytest]\nenv = FROM_INI=unexpected",
{"FROM_INI": None},
"pytest.toml",
id="empty pytest toml native over ini",
),
pytest.param(
{},
"",
"[pytest_env]\n",
"[pytest]\nenv = FROM_INI=unexpected",
{"FROM_INI": None},
".pytest.toml",
id="empty hidden pytest toml native over ini",
),
pytest.param(
{},
'[tool.pytest_env]\nMAGIC = {value = "toml", "transform"= true, "skip_if_set" = true}',
Expand Down Expand Up @@ -316,9 +343,8 @@ def test_env_via_toml(
"PYTEST_DISABLE_PLUGIN_AUTOLOAD": "1",
"PYTEST_PLUGINS": "pytest_env.plugin",
}

with mock.patch.dict(os.environ, new_env, clear=True):
result = pytester.runpytest(str(test_dir))
result = pytester.runpytest(*(("-c", str(pytester.path / "pytest.ini")) if ini else ()), str(test_dir))

result.assert_outcomes(passed=1)

Expand Down
Loading