diff options
author | Chris Down <chris@chrisdown.name> | 2022-01-13 07:40:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-13 07:40:56 +0000 |
commit | 9cc692d85c9ce84344ea7fee4b127755c6099a32 (patch) | |
tree | eb758db9008ecfc5d2e9b487df784efa892fec0a | |
parent | 86a0383c0617ff1d1ea47a526211bedc415c9d95 (diff) | |
download | tox-git-master.tar.gz |
venv: Do not fail for test commands that don't exist with "-" leader (#2316)master
-rw-r--r-- | CONTRIBUTORS | 1 | ||||
-rw-r--r-- | docs/changelog/2315.feature.rst | 2 | ||||
-rw-r--r-- | docs/config.rst | 2 | ||||
-rw-r--r-- | src/tox/venv.py | 12 | ||||
-rw-r--r-- | tests/unit/test_venv.py | 15 |
5 files changed, 30 insertions, 2 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 3b2700d6..ca325a32 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -24,6 +24,7 @@ Brett Smith Bruno Oliveira Carl Meyer Charles Brunet +Chris Down Chris Jerdonek Chris Rose Clark Boylan diff --git a/docs/changelog/2315.feature.rst b/docs/changelog/2315.feature.rst new file mode 100644 index 00000000..65411d6b --- /dev/null +++ b/docs/changelog/2315.feature.rst @@ -0,0 +1,2 @@ +Ignore missing commands if they are prefixed by ``-`` +-- by :user:`cdown`. diff --git a/docs/config.rst b/docs/config.rst index 231ccc05..8f277ffe 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -264,7 +264,7 @@ Complete list of settings that you can put into ``testenv*`` sections: Commands will execute one by one in sequential fashion until one of them fails (their exit code is non-zero) or all of them succeed. The exit code of a command may be ignored (meaning - they are always considered successful) by prefixing the command with a dash (``-``) - this is + they are always considered successful even if they don't exist) by prefixing the command with a dash (``-``) - this is similar to how ``make`` recipe lines work. The outcome of the environment is considered successful only if all commands (these + setup + teardown) succeeded (exit code ignored via the ``-`` or success exit code value of zero). diff --git a/src/tox/venv.py b/src/tox/venv.py index cdd6949a..87e01656 100644 --- a/src/tox/venv.py +++ b/src/tox/venv.py @@ -595,7 +595,17 @@ class VirtualEnv(object): reporter.verbosity2("setting PATH={}".format(env["PATH"])) # get command - args[0] = self.getcommandpath(args[0], venv, cwd) + try: + args[0] = self.getcommandpath(args[0], venv, cwd) + except tox.exception.InvocationError: + if ignore_ret: + self.status = getattr(self, "status", 0) + msg = "command not found but explicitly ignored" + reporter.warning("{}\ncmd: {}".format(msg, args[0])) + return "" # in case it's returnout + else: + raise + if sys.platform != "win32" and "TOX_LIMITED_SHEBANG" in os.environ: args = prepend_shebang_interpreter(args) diff --git a/tests/unit/test_venv.py b/tests/unit/test_venv.py index 2d019034..aa78a48b 100644 --- a/tests/unit/test_venv.py +++ b/tests/unit/test_venv.py @@ -980,6 +980,21 @@ def test_ignore_outcome_failing_cmd(newmocksession): mocksession.report.expect("warning", "*command failed but result from testenv is ignored*") +def test_ignore_outcome_missing_cmd(newmocksession): + mocksession = newmocksession( + [], + """\ + [testenv] + commands=-thiscommanddoesntexist + """, + ) + + venv = mocksession.getvenv("python") + venv.test() + assert venv.status == 0 + mocksession.report.expect("warning", "*command not found but explicitly ignored*") + + def test_tox_testenv_create(newmocksession): log = [] |