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

keep additional environments config order #903 #981

Merged
merged 1 commit into from
Sep 15, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/903.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
skip missing interpreters value from the config file can now be overridden via the ``--skip-missing-interpreters`` cli flag - by :user:`gaborbernat`
18 changes: 9 additions & 9 deletions doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ and will first lookup global tox settings in this section:
commands = ... # override [tox] settings for the jenkins context
# note: for jenkins distshare defaults to ``{toxworkdir}/distshare`` (DEPRECATED)

.. confval:: skip_missing_interpreters=BOOL
.. confval:: skip_missing_interpreters=config|true|false

.. versionadded:: 1.7.2

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

.. confval:: envlist=CSV

Expand Down
32 changes: 23 additions & 9 deletions src/tox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,8 @@ def tox_addoption(parser):
parser.add_argument(
"--alwayscopy", action="store_true", help="override alwayscopy setting to True in all envs"
)
parser.add_argument(
"--skip-missing-interpreters",
action="store_true",
help="don't fail tests for missing interpreters",
)

cli_skip_missing_interpreter(parser)
parser.add_argument(
"--workdir",
action="store",
Expand Down Expand Up @@ -780,6 +777,24 @@ def develop(testenv_config, value):
)


def cli_skip_missing_interpreter(parser):
class SkipMissingInterpreterAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
value = "true" if values is None else values
if value not in ("config", "true", "false"):
raise argparse.ArgumentTypeError("value must be config, true or false")
setattr(namespace, self.dest, value)

parser.add_argument(
"--skip-missing-interpreters",
default="config",
metavar="val",
nargs="?",
action=SkipMissingInterpreterAction,
help="don't fail tests for missing interpreters: {config,true,false} choice",
)


class Config(object):
"""Global Tox config object."""

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

if not config.option.skip_missing_interpreters:
config.option.skip_missing_interpreters = reader.getbool(
"skip_missing_interpreters", False
)
if config.option.skip_missing_interpreters == "config":
val = reader.getbool("skip_missing_interpreters", False)
config.option.skip_missing_interpreters = "true" if val else "false"

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

Expand Down
4 changes: 2 additions & 2 deletions src/tox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def setupenv(self, venv):
)
except tox.exception.InterpreterNotFound as e:
status = e
if self.config.option.skip_missing_interpreters:
if self.config.option.skip_missing_interpreters == "true":
default_ret_code = 0
if status:
str_status = str(status)
Expand Down Expand Up @@ -573,7 +573,7 @@ def _summary(self):
status = venv.status
if isinstance(status, tox.exception.InterpreterNotFound):
msg = " {}: {}".format(venv.envconfig.envname, str(status))
if self.config.option.skip_missing_interpreters:
if self.config.option.skip_missing_interpreters == "true":
self.report.skip(msg)
else:
retcode = 1
Expand Down
40 changes: 34 additions & 6 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,20 +1902,48 @@ def test_minversion(self, newconfig):
newconfig([], inisource)

def test_skip_missing_interpreters_true(self, newconfig):
inisource = """
ini_source = """
[tox]
skip_missing_interpreters = True
"""
config = newconfig([], inisource)
assert config.option.skip_missing_interpreters
config = newconfig([], ini_source)
assert config.option.skip_missing_interpreters == "true"

def test_skip_missing_interpreters_false(self, newconfig):
inisource = """
ini_source = """
[tox]
skip_missing_interpreters = False
"""
config = newconfig([], inisource)
assert not config.option.skip_missing_interpreters
config = newconfig([], ini_source)
assert config.option.skip_missing_interpreters == "false"

def test_skip_missing_interpreters_cli_no_arg(self, newconfig):
ini_source = """
[tox]
skip_missing_interpreters = False
"""
config = newconfig(["--skip-missing-interpreters"], ini_source)
assert config.option.skip_missing_interpreters == "true"

def test_skip_missing_interpreters_cli_not_specified(self, newconfig):
config = newconfig([], "")
assert config.option.skip_missing_interpreters == "false"

def test_skip_missing_interpreters_cli_overrides_true(self, newconfig):
ini_source = """
[tox]
skip_missing_interpreters = False
"""
config = newconfig(["--skip-missing-interpreters", "true"], ini_source)
assert config.option.skip_missing_interpreters == "true"

def test_skip_missing_interpreters_cli_overrides_false(self, newconfig):
ini_source = """
[tox]
skip_missing_interpreters = True
"""
config = newconfig(["--skip-missing-interpreters", "false"], ini_source)
assert config.option.skip_missing_interpreters == "false"

def test_defaultenv_commandline(self, newconfig):
config = newconfig(["-epy27"], "")
Expand Down