Skip to content

Commit

Permalink
Fix legacy devenv (#3019)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat committed May 27, 2023
1 parent 1c2601b commit accbc84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tox/session/env_select.py
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/session/test_env_select.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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"}

0 comments on commit accbc84

Please sign in to comment.