Skip to content

Commit

Permalink
Fix --skip-missing-interpreters (#2793)
Browse files Browse the repository at this point in the history
Closes #2649
  • Loading branch information
q0w committed Dec 30, 2022
1 parent 1d739a2 commit d8c4cb0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
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

0 comments on commit d8c4cb0

Please sign in to comment.