Skip to content

Commit

Permalink
Allow appending to deps with -x testenv.deps+=foo
Browse files Browse the repository at this point in the history
Fixes: #3256
  • Loading branch information
stefanor committed Apr 1, 2024
1 parent 1f0c075 commit b48e725
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog/3256.bugfix.rst
@@ -0,0 +1 @@
Allow appending to ``deps`` with ``--override testenv.deps+=foo`` - by :user:`stefanor`.
3 changes: 3 additions & 0 deletions src/tox/config/loader/api.py
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING, Any, List, Mapping, TypeVar

from tox.plugin import impl
from tox.tox_env.python.pip.req_file import PythonDeps

from .convert import Convert, Factory
from .str_convert import StrConvert
Expand Down Expand Up @@ -148,6 +149,8 @@ def load( # noqa: PLR0913
converted.update(converted_override)
elif isinstance(converted, SetEnv) and isinstance(converted_override, SetEnv):
converted.update(converted_override, override=True)
elif isinstance(converted, PythonDeps) and isinstance(converted_override, PythonDeps):
converted += converted_override
else:
msg = "Only able to append to lists and dicts"
raise ValueError(msg)
Expand Down
33 changes: 33 additions & 0 deletions tests/config/test_main.py
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
from functools import partial
from pathlib import Path
from typing import TYPE_CHECKING, List

Expand All @@ -9,6 +10,7 @@
from tox.config.loader.api import Override
from tox.config.loader.memory import MemoryLoader
from tox.config.sets import ConfigSet
from tox.tox_env.python.pip.req_file import PythonDeps

if TYPE_CHECKING:
from tests.conftest import ToxIniCreator
Expand Down Expand Up @@ -98,6 +100,37 @@ def test_config_override_appends_to_empty_setenv(tox_ini_conf: ToxIniCreator) ->
assert conf["setenv"].load("foo") == "bar"


def test_config_override_appends_to_pythondeps(tox_ini_conf: ToxIniCreator, tmp_path: Path) -> None:
example = """
[testenv]
deps = foo
"""
conf = tox_ini_conf(example, override=[Override("testenv.deps+=bar")]).get_env("testenv")
conf.add_config(
"deps",
of_type=PythonDeps,
factory=partial(PythonDeps.factory, tmp_path),
default=PythonDeps("", root=tmp_path),
desc="desc",
)
assert conf["deps"].lines() == ["foo", "bar"]


def test_config_override_appends_to_empty_pythondeps(tox_ini_conf: ToxIniCreator, tmp_path: Path) -> None:
example = """
[testenv]
"""
conf = tox_ini_conf(example, override=[Override("testenv.deps+=bar")]).get_env("testenv")
conf.add_config(
"deps",
of_type=PythonDeps,
factory=partial(PythonDeps.factory, tmp_path),
default=PythonDeps("", root=tmp_path),
desc="desc",
)
assert conf["deps"].lines() == ["bar"]


def test_config_override_cannot_append(tox_ini_conf: ToxIniCreator) -> None:
example = """
[testenv]
Expand Down

0 comments on commit b48e725

Please sign in to comment.