Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix legacy tox --devenv venv #3013

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2925.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``tox --devenv venv`` invocation without ``-e`` - by :user:`asottile`.
1 change: 1 addition & 0 deletions src/tox/session/cmd/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def legacy(state: State) -> int:
return list_env(state)
if option.devenv_path:
option.devenv_path = Path(option.devenv_path)
option.env = option.env or CliEnv("py")
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
return devenv(state)
if option.parallel != 0: # only 0 means sequential
return run_parallel(state)
Expand Down
5 changes: 4 additions & 1 deletion src/tox/session/env_select.py
Original file line number Diff line number Diff line change
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
13 changes: 11 additions & 2 deletions tests/session/cmd/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,22 @@ def test_legacy_list_all(tox_project: ToxProjectCreator, mocker: MockerFixture,
assert outcome.state.conf.options.show_core is False


def test_legacy_devenv(tox_project: ToxProjectCreator, mocker: MockerFixture, tmp_path: Path) -> None:
@pytest.mark.parametrize("args", [(), ("-e", "py")])
def test_legacy_devenv(
tox_project: ToxProjectCreator,
mocker: MockerFixture,
tmp_path: Path,
args: tuple[str, ...],
) -> None:
devenv = mocker.patch("tox.session.cmd.legacy.devenv")
into = tmp_path / "b"

outcome = tox_project({"tox.ini": ""}).run("le", "--devenv", str(into), "-e", "py")
outcome = tox_project({"tox.ini": ""}).run("le", "--devenv", str(into), *args)

outcome.state.envs.ensure_only_run_env_is_active()

assert devenv.call_count == 1
assert set(outcome.state.conf.options.env) == {"py"}
assert outcome.state.conf.options.devenv_path == into


Expand Down
11 changes: 11 additions & 0 deletions tests/session/test_env_select.py
Original file line number Diff line number Diff line change
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
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
state.conf.options.env = CliEnv("py")
assert set(env_selector.iter()) == {"py"}