Skip to content

Commit c8e07a4

Browse files
committed
skip missing interpreters config value can be overriden via cli flag
1 parent e4645ec commit c8e07a4

File tree

5 files changed

+69
-26
lines changed

5 files changed

+69
-26
lines changed

changelog/903.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
skip missing interpreters value from the config file can now be overridden via the ``--skip-missing-interpreters`` cli flag - by :user:`gaborbernat`

doc/config.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ and will first lookup global tox settings in this section:
5454
commands = ... # override [tox] settings for the jenkins context
5555
# note: for jenkins distshare defaults to ``{toxworkdir}/distshare`` (DEPRECATED)
5656
57-
.. confval:: skip_missing_interpreters=BOOL
57+
.. confval:: skip_missing_interpreters=config|true|false
5858

5959
.. versionadded:: 1.7.2
6060

61-
Setting this to ``True`` is equivalent of passing the
62-
``--skip-missing-interpreters`` command line option, and will force ``tox`` to
63-
return success even if some of the specified environments were missing. This is
64-
useful for some CI systems or running on a developer box, where you might only
65-
have a subset of all your supported interpreters installed but don't want to
66-
mark the build as failed because of it. As expected, the command line switch
67-
always overrides this setting if passed on the invokation.
68-
**Default:** ``False``
61+
When skip missing interpreters is ``true`` will force ``tox`` to return success even
62+
if some of the specified environments were missing. This is useful for some CI
63+
systems or running on a developer box, where you might only have a subset of
64+
all your supported interpreters installed but don't want to mark the build as
65+
failed because of it. As expected, the command line switch always overrides
66+
this setting if passed on the invocation. Setting it to ``config``
67+
means that the value is read from the config file (default is ``false``).
68+
**Default:** ``config``
6969

7070
.. confval:: envlist=CSV
7171

src/tox/config.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,8 @@ def tox_addoption(parser):
493493
parser.add_argument(
494494
"--alwayscopy", action="store_true", help="override alwayscopy setting to True in all envs"
495495
)
496-
parser.add_argument(
497-
"--skip-missing-interpreters",
498-
action="store_true",
499-
help="don't fail tests for missing interpreters",
500-
)
496+
497+
cli_skip_missing_interpreter(parser)
501498
parser.add_argument(
502499
"--workdir",
503500
action="store",
@@ -780,6 +777,24 @@ def develop(testenv_config, value):
780777
)
781778

782779

780+
def cli_skip_missing_interpreter(parser):
781+
class SkipMissingInterpreterAction(argparse.Action):
782+
def __call__(self, parser, namespace, values, option_string=None):
783+
value = "true" if values is None else values
784+
if value not in ("config", "true", "false"):
785+
raise argparse.ArgumentTypeError("value must be config, true or false")
786+
setattr(namespace, self.dest, value)
787+
788+
parser.add_argument(
789+
"--skip-missing-interpreters",
790+
default="config",
791+
metavar="val",
792+
nargs="?",
793+
action=SkipMissingInterpreterAction,
794+
help="don't fail tests for missing interpreters: {config,true,false} choice",
795+
)
796+
797+
783798
class Config(object):
784799
"""Global Tox config object."""
785800

@@ -947,10 +962,9 @@ def __init__(self, config, ini_path, ini_data): # noqa
947962
else:
948963
config.toxworkdir = config.toxinidir.join(config.option.workdir, abs=True)
949964

950-
if not config.option.skip_missing_interpreters:
951-
config.option.skip_missing_interpreters = reader.getbool(
952-
"skip_missing_interpreters", False
953-
)
965+
if config.option.skip_missing_interpreters == "config":
966+
val = reader.getbool("skip_missing_interpreters", False)
967+
config.option.skip_missing_interpreters = "true" if val else "false"
954968

955969
config.ignore_basepython_conflict = reader.getbool("ignore_basepython_conflict", False)
956970

src/tox/session.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def setupenv(self, venv):
470470
)
471471
except tox.exception.InterpreterNotFound as e:
472472
status = e
473-
if self.config.option.skip_missing_interpreters:
473+
if self.config.option.skip_missing_interpreters == "true":
474474
default_ret_code = 0
475475
if status:
476476
str_status = str(status)
@@ -573,7 +573,7 @@ def _summary(self):
573573
status = venv.status
574574
if isinstance(status, tox.exception.InterpreterNotFound):
575575
msg = " {}: {}".format(venv.envconfig.envname, str(status))
576-
if self.config.option.skip_missing_interpreters:
576+
if self.config.option.skip_missing_interpreters == "true":
577577
self.report.skip(msg)
578578
else:
579579
retcode = 1

tests/unit/test_config.py

+34-6
Original file line numberDiff line numberDiff line change
@@ -1902,20 +1902,48 @@ def test_minversion(self, newconfig):
19021902
newconfig([], inisource)
19031903

19041904
def test_skip_missing_interpreters_true(self, newconfig):
1905-
inisource = """
1905+
ini_source = """
19061906
[tox]
19071907
skip_missing_interpreters = True
19081908
"""
1909-
config = newconfig([], inisource)
1910-
assert config.option.skip_missing_interpreters
1909+
config = newconfig([], ini_source)
1910+
assert config.option.skip_missing_interpreters == "true"
19111911

19121912
def test_skip_missing_interpreters_false(self, newconfig):
1913-
inisource = """
1913+
ini_source = """
19141914
[tox]
19151915
skip_missing_interpreters = False
19161916
"""
1917-
config = newconfig([], inisource)
1918-
assert not config.option.skip_missing_interpreters
1917+
config = newconfig([], ini_source)
1918+
assert config.option.skip_missing_interpreters == "false"
1919+
1920+
def test_skip_missing_interpreters_cli_no_arg(self, newconfig):
1921+
ini_source = """
1922+
[tox]
1923+
skip_missing_interpreters = False
1924+
"""
1925+
config = newconfig(["--skip-missing-interpreters"], ini_source)
1926+
assert config.option.skip_missing_interpreters == "true"
1927+
1928+
def test_skip_missing_interpreters_cli_not_specified(self, newconfig):
1929+
config = newconfig([], "")
1930+
assert config.option.skip_missing_interpreters == "false"
1931+
1932+
def test_skip_missing_interpreters_cli_overrides_true(self, newconfig):
1933+
ini_source = """
1934+
[tox]
1935+
skip_missing_interpreters = False
1936+
"""
1937+
config = newconfig(["--skip-missing-interpreters", "true"], ini_source)
1938+
assert config.option.skip_missing_interpreters == "true"
1939+
1940+
def test_skip_missing_interpreters_cli_overrides_false(self, newconfig):
1941+
ini_source = """
1942+
[tox]
1943+
skip_missing_interpreters = True
1944+
"""
1945+
config = newconfig(["--skip-missing-interpreters", "false"], ini_source)
1946+
assert config.option.skip_missing_interpreters == "false"
19191947

19201948
def test_defaultenv_commandline(self, newconfig):
19211949
config = newconfig(["-epy27"], "")

0 commit comments

Comments
 (0)