From accbc844ecc1ef5085193d8a150522736431da1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Sat, 27 May 2023 16:11:25 -0700 Subject: [PATCH] Fix legacy devenv (#3019) --- src/tox/session/env_select.py | 5 ++++- tests/session/test_env_select.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/tox/session/env_select.py b/src/tox/session/env_select.py index f091474d4..5bb283b3c 100644 --- a/src/tox/session/env_select.py +++ b/src/tox/session/env_select.py @@ -125,7 +125,6 @@ def __init__(self, state: State) -> None: self.on_empty_fallback_py = True self._warned_about: set[str] = set() #: shared set of skipped environments that were already warned about self._state = state - self._cli_envs: CliEnv | None = getattr(self._state.conf.options, "env", None) self._defined_envs_: None | dict[str, _ToxEnvInfo] = None self._pkg_env_counter: Counter[str] = Counter() from tox.plugin.manager import MANAGER @@ -139,6 +138,10 @@ def __init__(self, state: State) -> None: tox_env_filter_regex = getattr(state.conf.options, "skip_env", "").strip() self._filter_re = re.compile(tox_env_filter_regex) if tox_env_filter_regex else None + @property + def _cli_envs(self) -> CliEnv | None: + return getattr(self._state.conf.options, "env", None) + def _collect_names(self) -> Iterator[tuple[Iterable[str], bool]]: """:return: sources of tox environments defined with name and if is marked as target to run""" if self._provision is not None: # pragma: no branch diff --git a/tests/session/test_env_select.py b/tests/session/test_env_select.py index 496107a37..e8378fc7e 100644 --- a/tests/session/test_env_select.py +++ b/tests/session/test_env_select.py @@ -2,7 +2,10 @@ import pytest +from tox.config.cli.parse import get_options from tox.pytest import MonkeyPatch, ToxProjectCreator +from tox.session.env_select import CliEnv, EnvSelector +from tox.session.state import State def test_label_core_can_define(tox_project: ToxProjectCreator) -> None: @@ -117,3 +120,11 @@ def test_tox_skip_env_logs(tox_project: ToxProjectCreator, monkeypatch: MonkeyPa outcome = project.run("l", "--no-desc") outcome.assert_success() outcome.assert_out_err("ROOT: skip environment mypy, matches filter 'm[y]py'\npy310\npy39\n", "") + + +def test_env_select_lazily_looks_at_envs() -> None: + state = State(get_options(), []) + env_selector = EnvSelector(state) + # late-assigning env should be reflected in env_selector + state.conf.options.env = CliEnv("py") + assert set(env_selector.iter()) == {"py"}