From 6a4174e0aeef61511a1bde5f9c00c731d27c56fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Gmach?= Date: Fri, 10 Sep 2021 10:00:15 +0200 Subject: Let tox run fail when all envs are skipped (#2206) --- docs/changelog/2195.feature.rst | 1 + src/tox/session/cmd/run/common.py | 6 ++++-- tests/session/cmd/test_sequential.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 docs/changelog/2195.feature.rst diff --git a/docs/changelog/2195.feature.rst b/docs/changelog/2195.feature.rst new file mode 100644 index 00000000..ae4d3f4c --- /dev/null +++ b/docs/changelog/2195.feature.rst @@ -0,0 +1 @@ +Let tox run fail when all envs are skipped -- by :user:`jugmac00`. diff --git a/src/tox/session/cmd/run/common.py b/src/tox/session/cmd/run/common.py index 857c59a7..7dd0a527 100644 --- a/src/tox/session/cmd/run/common.py +++ b/src/tox/session/cmd/run/common.py @@ -144,9 +144,10 @@ def report(start: float, runs: List[ToxEnvRunResult], is_colored: bool) -> int: def _print(color_: int, message: str) -> None: print(f"{color_ if is_colored else ''}{message}{Fore.RESET if is_colored else ''}") - all_good = True + successful, skipped = [], [] for run in runs: - all_good &= run.code == Outcome.OK or run.ignore_outcome + successful.append(run.code == Outcome.OK or run.ignore_outcome) + skipped.append(run.skipped) duration_individual = [o.elapsed for o in run.outcomes] extra = f"+cmd[{','.join(f'{i:.2f}' for i in duration_individual)}]" if duration_individual else "" setup = run.duration - sum(duration_individual) @@ -155,6 +156,7 @@ def report(start: float, runs: List[ToxEnvRunResult], is_colored: bool) -> int: _print(color, out) duration = time.monotonic() - start + all_good = all(successful) and not all(skipped) if all_good: _print(Fore.GREEN, f" congratulations :) ({duration:.2f} seconds)") return Outcome.OK diff --git a/tests/session/cmd/test_sequential.py b/tests/session/cmd/test_sequential.py index 35622b68..b358eecc 100644 --- a/tests/session/cmd/test_sequential.py +++ b/tests/session/cmd/test_sequential.py @@ -410,7 +410,7 @@ def test_platform_does_not_match_package_env(tox_project: ToxProjectCreator, dem ini = "[testenv]\npackage=wheel\n[testenv:.pkg]\nplatform=wrong_platform" proj = tox_project({"tox.ini": ini, "pyproject.toml": toml, "build.py": build}) result = proj.run("r", "-e", "a,b") - result.assert_success() + result.assert_failed() # tox run fails as all envs are skipped assert "a: SKIP" in result.out assert "b: SKIP" in result.out msg = f"skipped because platform {sys.platform} does not match wrong_platform for package environment .pkg" -- cgit v1.2.1