-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun_pytest_windows.py
More file actions
47 lines (38 loc) · 1.52 KB
/
run_pytest_windows.py
File metadata and controls
47 lines (38 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Windows pytest runner that isolates the pytest exit code from any
subsequent heap-corruption crash during Python interpreter shutdown.
Usage: python run_pytest_windows.py [pytest args...] --exitcode-file=<path>
The script runs pytest in a subprocess, captures the return code at the
Python level (before interpreter shutdown), writes it to a file, then
calls os._exit(0) to skip Python's shutdown machinery entirely.
This prevents the heap-corruption crash (0xC0000374) that occurs in
tttrlib's C extension destructors from affecting the step exit code.
The calling shell reads the exitcode file for the real pytest result.
"""
import subprocess
import sys
import os
def main():
args = sys.argv[1:]
exitcode_file = "pytest_exitcode.txt"
# Pull out --exitcode-file=<path> if present
filtered = []
for a in args:
if a.startswith("--exitcode-file="):
exitcode_file = a.split("=", 1)[1]
else:
filtered.append(a)
cmd = [sys.executable, "-m", "pytest"] + filtered
result = subprocess.run(cmd)
code = result.returncode
# Write exit code to file BEFORE any Python shutdown that could crash.
with open(exitcode_file, "w") as f:
f.write(str(code))
f.flush()
os.fsync(f.fileno())
# os._exit() bypasses all atexit handlers, __del__ methods, and the
# Python interpreter shutdown sequence entirely. This prevents the
# C extension destructor heap crash from killing this wrapper process.
os._exit(0)
if __name__ == "__main__":
main()