diff --git a/docs/changelog/4062.bugfix.rst b/docs/changelog/4062.bugfix.rst new file mode 100644 index 000000000..10e6c3903 --- /dev/null +++ b/docs/changelog/4062.bugfix.rst @@ -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`. diff --git a/src/tox/config/source/toml_pyproject.py b/src/tox/config/source/toml_pyproject.py index 47fa00f44..e53df8764 100644 --- a/src/tox/config/source/toml_pyproject.py +++ b/src/tox/config/source/toml_pyproject.py @@ -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 @@ -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 diff --git a/tests/config/source/test_toml_tox.py b/tests/config/source/test_toml_tox.py index f8104f2ef..db7fdcf56 100644 --- a/tests/config/source/test_toml_tox.py +++ b/tests/config/source/test_toml_tox.py @@ -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("""\