|
71 | 71 | "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink", |
72 | 72 | "skip_unless_xattr", "import_fresh_module", "requires_zlib", |
73 | 73 | "PIPE_MAX_SIZE", "failfast", "anticipate_failure", "run_with_tz", |
74 | | - "requires_bz2", "requires_lzma" |
| 74 | + "requires_bz2", "requires_lzma", "suppress_crash_popup", |
75 | 75 | ] |
76 | 76 |
|
77 | 77 | class Error(Exception): |
@@ -1905,6 +1905,28 @@ def skip_unless_xattr(test): |
1905 | 1905 | msg = "no non-broken extended attribute support" |
1906 | 1906 | return test if ok else unittest.skip(msg)(test) |
1907 | 1907 |
|
| 1908 | + |
| 1909 | +if sys.platform.startswith('win'): |
| 1910 | + @contextlib.contextmanager |
| 1911 | + def suppress_crash_popup(): |
| 1912 | + """Disable Windows Error Reporting dialogs using SetErrorMode.""" |
| 1913 | + # see http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621%28v=vs.85%29.aspx |
| 1914 | + import ctypes |
| 1915 | + k32 = ctypes.windll.kernel32 |
| 1916 | + old_error_mode = k32.GetErrorMode() |
| 1917 | + SEM_NOGPFAULTERRORBOX = 0x02 |
| 1918 | + k32.SetErrorMode(old_error_mode | SEM_NOGPFAULTERRORBOX) |
| 1919 | + try: |
| 1920 | + yield |
| 1921 | + finally: |
| 1922 | + k32.SetErrorMode(old_error_mode) |
| 1923 | +else: |
| 1924 | + # this is a no-op for other platforms |
| 1925 | + @contextlib.contextmanager |
| 1926 | + def suppress_crash_popup(): |
| 1927 | + yield |
| 1928 | + |
| 1929 | + |
1908 | 1930 | def patch(test_instance, object_to_patch, attr_name, new_value): |
1909 | 1931 | """Override 'object_to_patch'.'attr_name' with 'new_value'. |
1910 | 1932 |
|
|
0 commit comments