Skip to content

Commit d8c4cb0

Browse files
authored
Fix --skip-missing-interpreters (#2793)
Closes #2649
1 parent 1d739a2 commit d8c4cb0

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

docs/changelog/2649.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``--skip-missing-interpreters`` behaviour - by :user:`q0w`.

src/tox/session/cmd/run/single.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def _evaluate(tox_env: RunToxEnv, no_test: bool) -> tuple[bool, int, list[Outcom
4646
code, outcomes = run_commands(tox_env, no_test)
4747
except Skip as exception:
4848
LOGGER.warning("skipped because %s", exception)
49+
code = 0
4950
skipped = True
5051
except ToxBackendFailed as exception:
5152
LOGGER.error("%s", exception)

src/tox/tox_env/python/runner.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from tox.tox_env.package import Package
1414
from tox.tox_env.python.pip.req_file import PythonDeps
1515

16+
from ...config.loader.str_convert import StrConvert
1617
from ..api import ToxEnvCreateArgs
1718
from ..runner import RunToxEnv
1819
from .api import Python
@@ -32,10 +33,17 @@ def register_config(self) -> None:
3233
default=PythonDeps("", root),
3334
desc="Name of the python dependencies as specified by PEP-440",
3435
)
36+
37+
def skip_missing_interpreters_post_process(value: bool) -> bool:
38+
if getattr(self.options, "skip_missing_interpreters", "config") != "config":
39+
return StrConvert().to_bool(self.options.skip_missing_interpreters)
40+
return value
41+
3542
self.core.add_config(
3643
keys=["skip_missing_interpreters"],
3744
default=True,
3845
of_type=bool,
46+
post_process=skip_missing_interpreters_post_process,
3947
desc="skip running missing interpreters",
4048
)
4149

tests/tox_env/python/test_python_runner.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
from pathlib import Path
45

56
import pytest
@@ -121,3 +122,14 @@ def test_extras_are_normalized(
121122
result = project.run("c", "-e", "py", "--root", str(demo_pkg_inline), "-k", "extras")
122123
result.assert_success()
123124
assert result.out == f"[testenv:py]\nextras = {used_extra}\n"
125+
126+
127+
@pytest.mark.parametrize(
128+
("config", "cli", "expected"),
129+
[("false", "true", True), ("true", "false", False), ("false", "config", False), ("true", "config", True)],
130+
)
131+
def test_config_skip_missing_interpreters(tox_project: ToxProjectCreator, config: str, cli: str, expected: str) -> None:
132+
py_ver = ".".join(str(i) for i in sys.version_info[0:2])
133+
project = tox_project({"tox.ini": f"[tox]\nenvlist=py4,py{py_ver}\nskip_missing_interpreters={config}"})
134+
result = project.run("--skip-missing-interpreters", cli)
135+
assert result.code == 0 if expected else 1

0 commit comments

Comments
 (0)