Skip to content

Commit

Permalink
TOX-3117 bugfix -c pyproject with non legacy (#3471)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AdrianCert authored Jan 28, 2025
1 parent 851e987 commit 8d302eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/3117.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
multiple source_type supports for the same filename. Like pyproject.toml can be load by both TomlPyProject & LegacyToml
4 changes: 2 additions & 2 deletions src/tox/config/source/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def _locate_source() -> Source | None:

def _load_exact_source(config_file: Path) -> Source:
# if the filename matches to the letter some config file name do not fallback to other source types
exact_match = next((s for s in SOURCE_TYPES if config_file.name == s.FILENAME), None) # pragma: no cover
for src_type in (exact_match,) if exact_match is not None else SOURCE_TYPES: # pragma: no branch
exact_match = [s for s in SOURCE_TYPES if config_file.name == s.FILENAME] # pragma: no cover
for src_type in exact_match or SOURCE_TYPES: # pragma: no branch
try:
return src_type(config_file)
except ValueError: # noqa: PERF203
Expand Down
16 changes: 16 additions & 0 deletions tests/config/source/test_toml_pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ def test_config_in_toml_extra(tox_project: ToxProjectCreator) -> None:
assert "# !!! unused: " not in outcome.out, outcome.out


def test_config_in_toml_explicit_mentioned(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"pyproject.toml": """
[tool.tox.env_run_base]
description = "Do magical things"
commands = [
["python", "--version"]
]
"""
})

outcome = project.run("l", "-c", "pyproject.toml")
outcome.assert_success()
assert "could not recognize config file pyproject.toml" not in outcome.out, outcome.out


def test_config_in_toml_replace_default(tox_project: ToxProjectCreator) -> None:
project = tox_project({"pyproject.toml": '[tool.tox.env_run_base]\ndescription = "{missing:miss}"'})
outcome = project.run("c", "-k", "description")
Expand Down

0 comments on commit 8d302eb

Please sign in to comment.