summaryrefslogtreecommitdiffstats
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-03-05 18:33:38 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2013-03-05 18:33:38 (GMT)
commit87a249c1196bcdc09201f5b3c60ae13ecc62cbe1 (patch)
tree73142c432425721a253d7030a20e4b4d05f08f2d /Lib/test/support.py
parentdf1d3c5c4b5a235b4acd7700991363ad6fa8a3ca (diff)
parente1857d999d5547aa1ed99a76dad889b468a71222 (diff)
downloadcpython-87a249c1196bcdc09201f5b3c60ae13ecc62cbe1.zip
cpython-87a249c1196bcdc09201f5b3c60ae13ecc62cbe1.tar.gz
cpython-87a249c1196bcdc09201f5b3c60ae13ecc62cbe1.tar.bz2
#11732: merge with 3.3.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r--Lib/test/support.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index d886ad4..00b3664 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -71,7 +71,7 @@ __all__ = [
"TestHandler", "Matcher", "can_symlink", "skip_unless_symlink",
"skip_unless_xattr", "import_fresh_module", "requires_zlib",
"PIPE_MAX_SIZE", "failfast", "anticipate_failure", "run_with_tz",
- "requires_bz2", "requires_lzma"
+ "requires_bz2", "requires_lzma", "suppress_crash_popup",
]
class Error(Exception):
@@ -1907,6 +1907,28 @@ def skip_unless_xattr(test):
msg = "no non-broken extended attribute support"
return test if ok else unittest.skip(msg)(test)
+
+if sys.platform.startswith('win'):
+ @contextlib.contextmanager
+ def suppress_crash_popup():
+ """Disable Windows Error Reporting dialogs using SetErrorMode."""
+ # see http://msdn.microsoft.com/en-us/library/windows/desktop/ms680621%28v=vs.85%29.aspx
+ import ctypes
+ k32 = ctypes.windll.kernel32
+ old_error_mode = k32.GetErrorMode()
+ SEM_NOGPFAULTERRORBOX = 0x02
+ k32.SetErrorMode(old_error_mode | SEM_NOGPFAULTERRORBOX)
+ try:
+ yield
+ finally:
+ k32.SetErrorMode(old_error_mode)
+else:
+ # this is a no-op for other platforms
+ @contextlib.contextmanager
+ def suppress_crash_popup():
+ yield
+
+
def patch(test_instance, object_to_patch, attr_name, new_value):
"""Override 'object_to_patch'.'attr_name' with 'new_value'.