|
56 | 56 | "reap_children", "cpython_only", "check_impl_detail", "get_attribute", |
57 | 57 | "swap_item", "swap_attr", "requires_IEEE_754", |
58 | 58 | "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink", |
59 | | - "import_fresh_module", "failfast", "run_with_tz" |
| 59 | + "import_fresh_module", "failfast", "run_with_tz", "suppress_crash_popup", |
60 | 60 | ] |
61 | 61 |
|
62 | 62 | class Error(Exception): |
@@ -1775,6 +1775,30 @@ def skip_unless_symlink(test): |
1775 | 1775 | msg = "Requires functional symlink implementation" |
1776 | 1776 | return test if ok else unittest.skip(msg)(test) |
1777 | 1777 |
|
| 1778 | + |
| 1779 | +if sys.platform.startswith('win'): |
| 1780 | + @contextlib.contextmanager |
| 1781 | + def suppress_crash_popup(): |
| 1782 | + """Disable Windows Error Reporting dialogs using SetErrorMode.""" |
| 1783 | + # see http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621%28v=vs.85%29.aspx |
| 1784 | + # GetErrorMode is not available on Windows XP and Windows Server 2003, |
| 1785 | + # but SetErrorMode returns the previous value, so we can use that |
| 1786 | + import ctypes |
| 1787 | + k32 = ctypes.windll.kernel32 |
| 1788 | + SEM_NOGPFAULTERRORBOX = 0x02 |
| 1789 | + old_error_mode = k32.SetErrorMode(SEM_NOGPFAULTERRORBOX) |
| 1790 | + k32.SetErrorMode(old_error_mode | SEM_NOGPFAULTERRORBOX) |
| 1791 | + try: |
| 1792 | + yield |
| 1793 | + finally: |
| 1794 | + k32.SetErrorMode(old_error_mode) |
| 1795 | +else: |
| 1796 | + # this is a no-op for other platforms |
| 1797 | + @contextlib.contextmanager |
| 1798 | + def suppress_crash_popup(): |
| 1799 | + yield |
| 1800 | + |
| 1801 | + |
1778 | 1802 | def patch(test_instance, object_to_patch, attr_name, new_value): |
1779 | 1803 | """Override 'object_to_patch'.'attr_name' with 'new_value'. |
1780 | 1804 |
|
|
0 commit comments