Skip to content
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 CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Brett Smith
Bruno Oliveira
Carl Meyer
Charles Brunet
Chris Down
Chris Jerdonek
Chris Rose
Clark Boylan
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog/2315.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ignore missing commands if they are prefixed by ``-``
-- by :user:`cdown`.
2 changes: 1 addition & 1 deletion docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
12 changes: 11 additions & 1 deletion src/tox/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,17 @@ def _pcall(
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)

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down