Skip to content

Commit 8d302eb

Browse files
authored
TOX-3117 bugfix -c pyproject with non legacy (#3471)
Running tox -c pyproject.toml with content not ini legacy end up with a failure: could not recognize config file pyproject.toml [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci
1 parent 851e987 commit 8d302eb

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

docs/changelog/3117.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
multiple source_type supports for the same filename. Like pyproject.toml can be load by both TomlPyProject & LegacyToml

src/tox/config/source/discover.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def _locate_source() -> Source | None:
6868

6969
def _load_exact_source(config_file: Path) -> Source:
7070
# if the filename matches to the letter some config file name do not fallback to other source types
71-
exact_match = next((s for s in SOURCE_TYPES if config_file.name == s.FILENAME), None) # pragma: no cover
72-
for src_type in (exact_match,) if exact_match is not None else SOURCE_TYPES: # pragma: no branch
71+
exact_match = [s for s in SOURCE_TYPES if config_file.name == s.FILENAME] # pragma: no cover
72+
for src_type in exact_match or SOURCE_TYPES: # pragma: no branch
7373
try:
7474
return src_type(config_file)
7575
except ValueError: # noqa: PERF203

tests/config/source/test_toml_pyproject.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ def test_config_in_toml_extra(tox_project: ToxProjectCreator) -> None:
6464
assert "# !!! unused: " not in outcome.out, outcome.out
6565

6666

67+
def test_config_in_toml_explicit_mentioned(tox_project: ToxProjectCreator) -> None:
68+
project = tox_project({
69+
"pyproject.toml": """
70+
[tool.tox.env_run_base]
71+
description = "Do magical things"
72+
commands = [
73+
["python", "--version"]
74+
]
75+
"""
76+
})
77+
78+
outcome = project.run("l", "-c", "pyproject.toml")
79+
outcome.assert_success()
80+
assert "could not recognize config file pyproject.toml" not in outcome.out, outcome.out
81+
82+
6783
def test_config_in_toml_replace_default(tox_project: ToxProjectCreator) -> None:
6884
project = tox_project({"pyproject.toml": '[tool.tox.env_run_base]\ndescription = "{missing:miss}"'})
6985
outcome = project.run("c", "-k", "description")

0 commit comments

Comments
 (0)