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
4 changes: 3 additions & 1 deletion src/pytest_env/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def _find_toml_config(early_config: pytest.Config) -> Path | None:
def _config_source(early_config: pytest.Config) -> str:
"""Describe the configuration source for verbose output."""
if toml_path := _find_toml_config(early_config):
return str(toml_path)
_, entries = _load_toml_config(toml_path)
if entries:
return str(toml_path)
if early_config.inipath:
return str(early_config.inipath)
return "config" # pragma: no cover
Expand Down
26 changes: 25 additions & 1 deletion tests/test_verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,31 @@ def test_verbose_shows_set_from_ini(pytester: pytest.Pytester) -> None:
result = pytester.runpytest("--pytest-env-verbose")

result.assert_outcomes(passed=1)
result.stdout.fnmatch_lines(["*pytest-env:*", "*SET*MAGIC=alpha*"])
result.stdout.fnmatch_lines(["*pytest-env:*", "*SET*MAGIC=alpha*(from*pytest.ini*"])


def test_verbose_shows_ini_source_when_pyproject_lacks_pytest_env(pytester: pytest.Pytester) -> None:
(pytester.path / "test_it.py").symlink_to(Path(__file__).parent / "template.py")
(pytester.path / "pyproject.toml").write_text(
dedent("""\
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
"""),
encoding="utf-8",
)
(pytester.path / "pytest.ini").write_text("[pytest]\nenv = MAGIC=alpha", encoding="utf-8")

new_env = {
"_TEST_ENV": repr({"MAGIC": "alpha"}),
"PYTEST_DISABLE_PLUGIN_AUTOLOAD": "1",
"PYTEST_PLUGINS": "pytest_env.plugin",
}
with mock.patch.dict(os.environ, new_env, clear=True):
result = pytester.runpytest("--pytest-env-verbose")

result.assert_outcomes(passed=1)
result.stdout.fnmatch_lines(["*SET*MAGIC=alpha*(from*pytest.ini*"])


def test_verbose_shows_set_from_toml(pytester: pytest.Pytester) -> None:
Expand Down