diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index 6a33cf48dc5..d7d6df00981 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -811,7 +811,13 @@ def _handle_config_settings( if dest is None: dest = {} setattr(parser.values, option.dest, dest) - dest[key] = val + if key in dest: + if isinstance(dest[key], list): + dest[key].append(val) + else: + dest[key] = [dest[key], val] + else: + dest[key] = val config_settings: Callable[..., Option] = partial( diff --git a/tests/unit/test_pyproject_config.py b/tests/unit/test_pyproject_config.py index 9937f3880aa..ce6fbc6e2ab 100644 --- a/tests/unit/test_pyproject_config.py +++ b/tests/unit/test_pyproject_config.py @@ -36,9 +36,16 @@ def test_set_config_empty_value() -> None: assert options.config_settings == {"x": ""} -def test_replace_config_value() -> None: +@pytest.mark.parametrize( + ("passed", "expected"), + [ + (["x=hello", "x=world"], {"x": ["hello", "world"]}), + (["x=hello", "x=world", "x=other"], {"x": ["hello", "world", "other"]}), + ], +) +def test_multiple_config_values(passed, expected) -> None: i = create_command("install") options, _ = i.parse_args( - ["xxx", "--config-settings", "x=hello", "--config-settings", "x=world"] + ["xxx", *(f"--config-settings={option}" for option in passed)] ) - assert options.config_settings == {"x": "world"} + assert options.config_settings == expected