Skip to content

Commit

Permalink
Return non-zero error code on skipped env
Browse files Browse the repository at this point in the history
In #2206, we said that tox should fail if all envs are skipped. This is
broken when only a single env runs. We print an error message but return
0. Correct this behavior.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #2827
  • Loading branch information
stephenfin committed Jan 6, 2023
1 parent ac5dcb3 commit 5505c82
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/2827.bugfix.rst
@@ -0,0 +1,2 @@
tox returns a non-zero error code if all envs are skipped. It will now correctly do this if only a single env was
requested and this was skipped.
4 changes: 3 additions & 1 deletion src/tox/session/cmd/run/common.py
Expand Up @@ -187,7 +187,9 @@ def _print(color_: int, message: str) -> None:
_print(Fore.GREEN, f" congratulations :) ({duration:.2f} seconds)")
return Outcome.OK
_print(Fore.RED, f" evaluation failed :( ({duration:.2f} seconds)")
return runs[0].code if len(runs) == 1 else -1
if len(runs) == 1:
return runs[0].code if not runs[0].skipped else -1
return -1


def _get_outcome_message(run: ToxEnvRunResult) -> tuple[str, int]:
Expand Down
4 changes: 2 additions & 2 deletions tests/session/cmd/test_sequential.py
Expand Up @@ -224,7 +224,7 @@ def test_missing_interpreter_skip_on(tox_project: ToxProjectCreator) -> None:
proj = tox_project({"tox.ini": ini})

result = proj.run("r")
result.assert_success()
result.assert_failed()
assert "py: SKIP" in result.out


Expand Down Expand Up @@ -367,7 +367,7 @@ def test_platform_does_not_match_run_env(tox_project: ToxProjectCreator) -> None
proj = tox_project({"tox.ini": ini})

result = proj.run("r")
result.assert_success()
result.assert_failed()
exp = f"py: skipped because platform {sys.platform} does not match wrong_platform"
assert exp in result.out

Expand Down
2 changes: 1 addition & 1 deletion tests/tox_env/python/test_python_runner.py
Expand Up @@ -145,7 +145,7 @@ def test_config_skip_missing_interpreters(
[
("true", f"py{''.join(str(i) for i in sys.version_info[0:2])}", 0),
("false", f"py{''.join(str(i) for i in sys.version_info[0:2])}", 0),
("true", "py31", 0),
("true", "py31", -1),
("false", "py31", 1),
("true", None, 0),
("false", None, -1),
Expand Down

0 comments on commit 5505c82

Please sign in to comment.