File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,9 @@ def _find_toml_config(early_config: pytest.Config) -> Path | None:
146146def _config_source (early_config : pytest .Config ) -> str :
147147 """Describe the configuration source for verbose output."""
148148 if toml_path := _find_toml_config (early_config ):
149- return str (toml_path )
149+ _ , entries = _load_toml_config (toml_path )
150+ if entries :
151+ return str (toml_path )
150152 if early_config .inipath :
151153 return str (early_config .inipath )
152154 return "config" # pragma: no cover
Original file line number Diff line number Diff line change @@ -23,7 +23,31 @@ def test_verbose_shows_set_from_ini(pytester: pytest.Pytester) -> None:
2323 result = pytester .runpytest ("--pytest-env-verbose" )
2424
2525 result .assert_outcomes (passed = 1 )
26- result .stdout .fnmatch_lines (["*pytest-env:*" , "*SET*MAGIC=alpha*" ])
26+ result .stdout .fnmatch_lines (["*pytest-env:*" , "*SET*MAGIC=alpha*(from*pytest.ini*" ])
27+
28+
29+ def test_verbose_shows_ini_source_when_pyproject_lacks_pytest_env (pytester : pytest .Pytester ) -> None :
30+ (pytester .path / "test_it.py" ).symlink_to (Path (__file__ ).parent / "template.py" )
31+ (pytester .path / "pyproject.toml" ).write_text (
32+ dedent ("""\
33+ [build-system]
34+ requires = ["setuptools>=61"]
35+ build-backend = "setuptools.build_meta"
36+ """ ),
37+ encoding = "utf-8" ,
38+ )
39+ (pytester .path / "pytest.ini" ).write_text ("[pytest]\n env = MAGIC=alpha" , encoding = "utf-8" )
40+
41+ new_env = {
42+ "_TEST_ENV" : repr ({"MAGIC" : "alpha" }),
43+ "PYTEST_DISABLE_PLUGIN_AUTOLOAD" : "1" ,
44+ "PYTEST_PLUGINS" : "pytest_env.plugin" ,
45+ }
46+ with mock .patch .dict (os .environ , new_env , clear = True ):
47+ result = pytester .runpytest ("--pytest-env-verbose" )
48+
49+ result .assert_outcomes (passed = 1 )
50+ result .stdout .fnmatch_lines (["*SET*MAGIC=alpha*(from*pytest.ini*" ])
2751
2852
2953def test_verbose_shows_set_from_toml (pytester : pytest .Pytester ) -> None :
You can’t perform that action at this time.
0 commit comments