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 --skip-missing-interpreters #2793

Merged
merged 3 commits into from Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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/2649.bugfix.rst
@@ -0,0 +1 @@
Fix ``--skip-missing-interpreters`` behaviour - by :user:`q0w`.
1 change: 1 addition & 0 deletions src/tox/session/cmd/run/single.py
Expand Up @@ -46,6 +46,7 @@ def _evaluate(tox_env: RunToxEnv, no_test: bool) -> tuple[bool, int, list[Outcom
code, outcomes = run_commands(tox_env, no_test)
except Skip as exception:
LOGGER.warning("skipped because %s", exception)
code = 0
skipped = True
except ToxBackendFailed as exception:
LOGGER.error("%s", exception)
Expand Down
8 changes: 8 additions & 0 deletions src/tox/tox_env/python/runner.py
Expand Up @@ -13,6 +13,7 @@
from tox.tox_env.package import Package
from tox.tox_env.python.pip.req_file import PythonDeps

from ...config.loader.str_convert import StrConvert
from ..api import ToxEnvCreateArgs
from ..runner import RunToxEnv
from .api import Python
Expand All @@ -32,10 +33,17 @@ def register_config(self) -> None:
default=PythonDeps("", root),
desc="Name of the python dependencies as specified by PEP-440",
)

def skip_missing_interpreters_post_process(value: bool) -> bool:
if getattr(self.options, "skip_missing_interpreters", "config") != "config":
return StrConvert().to_bool(self.options.skip_missing_interpreters)
return value

self.core.add_config(
keys=["skip_missing_interpreters"],
default=True,
of_type=bool,
post_process=skip_missing_interpreters_post_process,
desc="skip running missing interpreters",
)

Expand Down
12 changes: 12 additions & 0 deletions tests/tox_env/python/test_python_runner.py
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
from pathlib import Path

import pytest
Expand Down Expand Up @@ -121,3 +122,14 @@ def test_extras_are_normalized(
result = project.run("c", "-e", "py", "--root", str(demo_pkg_inline), "-k", "extras")
result.assert_success()
assert result.out == f"[testenv:py]\nextras = {used_extra}\n"


@pytest.mark.parametrize(
("config", "cli", "expected"),
[("false", "true", True), ("true", "false", False), ("false", "config", False), ("true", "config", True)],
)
def test_config_skip_missing_interpreters(tox_project: ToxProjectCreator, config: str, cli: str, expected: str) -> None:
py_ver = ".".join(str(i) for i in sys.version_info[0:2])
project = tox_project({"tox.ini": f"[tox]\nenvlist=py4,py{py_ver}\nskip_missing_interpreters={config}"})
result = project.run("--skip-missing-interpreters", cli)
assert result.code == 0 if expected else 1