From 29179b12783bbd4d3927914b8476dff69b07e119 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 1 May 2015 15:29:07 -0700 Subject: Abort command execution when a command fails by default It's pretty meaningless to keep executing commands when one command fails. So let's make it abort by default if any command returns a non-zero exit code. E.g.: $ tox py27 runtests: PYTHONHASHSEED='2154811636' py27 runtests: commands[0] | echo 1 1 py27 runtests: commands[1] | false ERROR: InvocationError: '/usr/bin/false' ERROR: Stopping processing of commands for env py27 because `/usr/bin/false` failed with exit code 1 _____________________________________________ summary ______________________________________________ ERROR: py27: commands failed Unless the `ignore_errors` setting is set to `True`, in which case, it keeps processing, like it did in older versions of tox. --- tox/_cmdline.py | 2 +- tox/_config.py | 1 + tox/_venv.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tox/_cmdline.py b/tox/_cmdline.py index 0236d17..43fe5bc 100644 --- a/tox/_cmdline.py +++ b/tox/_cmdline.py @@ -157,7 +157,7 @@ class Action(object): raise tox.exception.InvocationError( "%s (see %s)" % (invoked, outpath), ret) else: - raise tox.exception.InvocationError("%r" % (invoked, )) + raise tox.exception.InvocationError("%r" % (invoked, ), ret) if not out and outpath: out = outpath.read() if hasattr(self, "commandlog"): diff --git a/tox/_config.py b/tox/_config.py index 4468d86..afb6544 100644 --- a/tox/_config.py +++ b/tox/_config.py @@ -442,6 +442,7 @@ class parseini: section, "pip_pre", False) vc.skip_install = reader.getbool(section, "skip_install", False) + vc.ignore_errors = reader.getbool(section, "ignore_errors", False) return vc diff --git a/tox/_venv.py b/tox/_venv.py index 9114e69..762e684 100644 --- a/tox/_venv.py +++ b/tox/_venv.py @@ -361,6 +361,14 @@ class VirtualEnv(object): val = sys.exc_info()[1] self.session.report.error(str(val)) self.status = "commands failed" + if not self.envconfig.ignore_errors: + self.session.report.error( + 'Stopping processing of commands for env %s ' + 'because `%s` failed with exit code %s' + % (self.name, + ' '.join([str(x) for x in argv]), + val.args[1])) + break # Don't process remaining commands except KeyboardInterrupt: self.status = "keyboardinterrupt" self.session.report.error(self.status) -- cgit v1.2.1 From 825ee1cb265904b2e80b38645f4ed4ddd808b849 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 5 May 2015 08:33:13 -0700 Subject: test_config: Add some tests for new ignore_errors setting --- tests/test_config.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index 79c98bd..e4e7bf6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -587,6 +587,7 @@ class TestConfigTestEnv: assert envconfig.changedir == config.setupdir assert envconfig.sitepackages is False assert envconfig.develop is False + assert envconfig.ignore_errors is False assert envconfig.envlogdir == envconfig.envdir.join("log") assert list(envconfig.setenv.keys()) == ['PYTHONHASHSEED'] hashseed = envconfig.setenv['PYTHONHASHSEED'] @@ -647,6 +648,15 @@ class TestConfigTestEnv: assert envconfig.changedir.basename == "xyz" assert envconfig.changedir == config.toxinidir.join("xyz") + def test_ignore_errors(self, tmpdir, newconfig): + config = newconfig(""" + [testenv] + ignore_errors=True + """) + assert len(config.envconfigs) == 1 + envconfig = config.envconfigs['python'] + assert envconfig.ignore_errors is True + def test_envbindir(self, tmpdir, newconfig): config = newconfig(""" [testenv] -- cgit v1.2.1 From 5a66d75cb644e1b88956e95f7ab9ff05cb06e58f Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 5 May 2015 09:02:27 -0700 Subject: doc/config.txt: Document new ignore_errors setting --- doc/config.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/config.txt b/doc/config.txt index d2d2854..22b4de1 100644 --- a/doc/config.txt +++ b/doc/config.txt @@ -110,6 +110,26 @@ Complete list of settings that you can put into ``testenv*`` sections: pip install {opts} {packages} +.. confval:: ignore_errors=True|False(default) + + .. versionadded:: 2.0 + + If ``True``, a non-zero exit code from one command will be ignored and + further commands will be executed (which was the default behavior in tox < + 2.0). If ``False`` (the default), then a non-zero exit code from one command + will abort execution of commands for that environment. + + It may be helpful to note that this setting is analogous to the ``-i`` or + ``ignore-errors`` option of GNU Make. A similar name was chosen to reflect the + similarity in function. + + Note that in tox 2.0, the default behavior of tox with respect to + treating errors from commands changed. Tox < 2.0 would ignore errors by + default. Tox >= 2.0 will abort on an error by default, which is safer and more + typical of CI and command execution tools, as it doesn't make sense to + run tests if installing some prerequisite failed and it doesn't make sense to + try to deploy if tests failed. + .. confval:: pip_pre=True|False(default) .. versionadded:: 1.9 -- cgit v1.2.1 From 294d91209ee5766e1ec23434c3b8efe25767cad1 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 5 May 2015 09:02:51 -0700 Subject: CHANGELOG: Document new "ignore_errors" setting --- CHANGELOG | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 29008b0..a578a44 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,12 @@ If platform is set and doesn't match the platform spec in the test environment the test environment is ignored, no setup or tests are attempted. +.. (new) add per-venv "ignore_errors" setting, which defaults to False. + If ``True``, a non-zero exit code from one command will be ignored and + further commands will be executed (which was the default behavior in tox < + 2.0). If ``False`` (the default), then a non-zero exit code from one command + will abort execution of commands for that environment. + - remove the long-deprecated "distribute" option as it has no effect these days. - fix issue233: avoid hanging with tox-setuptools integration example. Thanks simonb. -- cgit v1.2.1