Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/changelog/4062.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Register the ``{factor:label}`` name for a bare labeled dict in ``env_list``, as the configuration reference documents;
previously only a labeled group nested inside a ``product`` dict registered one - by :user:`dylanpulver`.
7 changes: 6 additions & 1 deletion src/tox/config/source/toml_pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ def _extract_env_list_labels(env_list_raw: TomlTypes) -> dict[str, FactorGroup]:
return {}
labels: dict[str, FactorGroup] = {}
for item in env_list_raw:
if isinstance(item, dict) and "product" in item:
if not isinstance(item, dict):
continue
if "product" in item:
raw_groups = item["product"]
if not isinstance(raw_groups, list):
continue
Expand All @@ -229,6 +231,9 @@ def _extract_env_list_labels(env_list_raw: TomlTypes) -> dict[str, FactorGroup]:
labels[str(idx)] = group
if (label := extract_label(g)) is not None:
labels[label] = group
elif (label := extract_label(item)) is not None: # a bare labeled dict is its own single factor group
values = expand_factor_group(item)
labels[label] = FactorGroup(values=values, default=extract_default(item, values))
return labels


Expand Down
40 changes: 40 additions & 0 deletions tests/config/source/test_toml_tox.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,46 @@ def test_config_in_toml_replace_from_section_absolute(tox_project: ToxProjectCre
outcome.assert_out_err("[testenv:B]\ndescription = o\n", "")


def test_config_in_toml_env_list_bare_labeled_factor_description(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": textwrap.dedent("""\
env_list = [
{ ecosystem = ["oci", "python"] },
]

[env_run_base]
package = "skip"
description = "Sync {factor:ecosystem} artifacts"
commands = [["python", "-c", "print('ok')"]]
"""),
})
outcome = project.run("c", "-e", "oci", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:oci]\ndescription = Sync oci artifacts\n", "")
outcome = project.run("c", "-e", "python", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:python]\ndescription = Sync python artifacts\n", "")


def test_config_in_toml_env_list_bare_labeled_factor_default(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": textwrap.dedent("""\
env_list = [
{ ecosystem = { values = ["oci", "python"], default = "oci" } },
]

[env_run_base]
package = "skip"

[env.lint]
description = "Lint {factor:ecosystem} artifacts"
"""),
})
outcome = project.run("c", "-e", "lint", "-k", "description")
outcome.assert_success()
outcome.assert_out_err("[testenv:lint]\ndescription = Lint oci artifacts\n", "")


def test_config_in_toml_env_list_keyed_factor_description(tox_project: ToxProjectCreator) -> None:
project = tox_project({
"tox.toml": textwrap.dedent("""\
Expand Down
Loading