diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2013-03-05 18:33:38 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2013-03-05 18:33:38 (GMT) |
commit | 87a249c1196bcdc09201f5b3c60ae13ecc62cbe1 (patch) | |
tree | 73142c432425721a253d7030a20e4b4d05f08f2d /Lib/test | |
parent | df1d3c5c4b5a235b4acd7700991363ad6fa8a3ca (diff) | |
parent | e1857d999d5547aa1ed99a76dad889b468a71222 (diff) | |
download | cpython-87a249c1196bcdc09201f5b3c60ae13ecc62cbe1.zip cpython-87a249c1196bcdc09201f5b3c60ae13ecc62cbe1.tar.gz cpython-87a249c1196bcdc09201f5b3c60ae13ecc62cbe1.tar.bz2 |
#11732: merge with 3.3.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/support.py | 24 | ||||
-rw-r--r-- | Lib/test/test_capi.py | 11 | ||||
-rw-r--r-- | Lib/test/test_faulthandler.py | 6 |
3 files changed, 33 insertions, 8 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'. diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 65778be..f1ea5a9 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -44,11 +44,12 @@ class CAPITest(unittest.TestCase): @unittest.skipUnless(threading, 'Threading required for this test.') def test_no_FatalError_infinite_loop(self): - p = subprocess.Popen([sys.executable, "-c", - 'import _testcapi;' - '_testcapi.crash_no_current_thread()'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + with support.suppress_crash_popup(): + p = subprocess.Popen([sys.executable, "-c", + 'import _testcapi;' + '_testcapi.crash_no_current_thread()'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) (out, err) = p.communicate() self.assertEqual(out, b'') # This used to cause an infinite loop. diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index b81b34d..c171faf 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -101,7 +101,8 @@ class FaultHandlerTests(unittest.TestCase): header=re.escape(header)) if other_regex: regex += '|' + other_regex - output, exitcode = self.get_output(code, filename) + with support.suppress_crash_popup(): + output, exitcode = self.get_output(code, filename) output = '\n'.join(output) self.assertRegex(output, regex) self.assertNotEqual(exitcode, 0) @@ -229,7 +230,8 @@ faulthandler.disable() faulthandler._read_null() """.strip() not_expected = 'Fatal Python error' - stderr, exitcode = self.get_output(code) + with support.suppress_crash_popup(): + stderr, exitcode = self.get_output(code) stder = '\n'.join(stderr) self.assertTrue(not_expected not in stderr, "%r is present in %r" % (not_expected, stderr)) |