Skip to content
This repository was archived by the owner on Aug 2, 2019. It is now read-only.

Commit 46da609

Browse files
committed
avoid windows-app crashes opening a dialog box for single tests
1 parent fa99ff7 commit 46da609

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pytest.py

+15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
if __name__ == '__main__': # if run as a script or by 'python -m pytest'
99
# we trigger the below "else" condition by the following import
1010
import pytest
11+
import sys
12+
if sys.platform == 'win32':
13+
#Try to avoid opeing a dialog box if one of the tests causes a system error
14+
import ctypes
15+
winapi = ctypes.windll.kernel32
16+
SetErrorMode = winapi.SetErrorMode
17+
SetErrorMode.argtypes=[ctypes.c_int]
18+
19+
SEM_FAILCRITICALERRORS = 1
20+
SEM_NOGPFAULTERRORBOX = 2
21+
SEM_NOOPENFILEERRORBOX = 0x8000
22+
flags = SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX
23+
#Since there is no GetErrorMode, do a double Set
24+
old_mode = SetErrorMode(flags)
25+
SetErrorMode(old_mode | flags)
1126
raise SystemExit(pytest.main())
1227

1328
# else we are imported

0 commit comments

Comments
 (0)