Skip to content

Commit 791405f

Browse files
committed
test(ci): run the Windows exit-status check under Git Bash, not the WSL stub
On the Windows runner bash on PATH was System32's WSL launcher, which exits 1 without running the script.
1 parent 997dff0 commit 791405f

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

‎tests/unit/test_ci_exit_status.py‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,39 @@
22

33
from __future__ import annotations
44

5+
import os
56
import shutil
67
import subprocess
8+
import sys
79
from pathlib import Path
810

911
import pytest
1012
import yaml
1113

1214

13-
@pytest.mark.skipif(shutil.which("bash") is None, reason="CI invokes pytest with bash")
15+
def _bash() -> str | None:
16+
"""The bash the workflow's ``shell: bash`` runs, never the WSL launcher.
17+
18+
On a Windows runner ``bash`` on PATH can resolve to System32's WSL stub,
19+
which exits 1 ("no installed distributions") without running anything,
20+
so every case but exit status 1 failed. GitHub's ``shell: bash`` is Git
21+
Bash.
22+
"""
23+
if sys.platform != "win32":
24+
return shutil.which("bash")
25+
windir = os.environ.get("SystemRoot", r"C:\Windows").lower()
26+
for folder in os.environ.get("PATH", "").split(os.pathsep):
27+
found = shutil.which("bash", path=folder) if folder else None
28+
if found and not (found.lower().startswith(windir) or "windowsapps" in found.lower()):
29+
return found
30+
default = Path(os.environ.get("ProgramFiles", r"C:\Program Files")) / "Git" / "bin" / "bash.exe"
31+
return str(default) if default.is_file() else None
32+
33+
34+
BASH = _bash()
35+
36+
37+
@pytest.mark.skipif(BASH is None, reason="CI invokes pytest with bash")
1438
@pytest.mark.parametrize("exit_status", [0, 1, 2, 3, 4, 5, 130])
1539
def test_windows_ci_preserves_pytest_exit_status(tmp_path, exit_status):
1640
workflow_path = Path(__file__).resolve().parents[2] / ".github" / "workflows" / "ci.yml"
@@ -22,7 +46,7 @@ def test_windows_ci_preserves_pytest_exit_status(tmp_path, exit_status):
2246
fake_pytest = f"pytest() {{ printf '1 passed\\n'; return {exit_status}; }}\n"
2347

2448
result = subprocess.run(
25-
["bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c", fake_pytest + step["run"]],
49+
[BASH, "--noprofile", "--norc", "-e", "-o", "pipefail", "-c", fake_pytest + step["run"]],
2650
cwd=tmp_path,
2751
capture_output=True,
2852
text=True,

0 commit comments

Comments
 (0)