(original) (raw)

changeset: 82500:b87123015fb0 parent: 82497:b0890674bc21 parent: 82499:ef7565180b48 user: Ezio Melotti ezio.melotti@gmail.com date: Tue Mar 05 20:33:38 2013 +0200 files: Lib/test/support.py Misc/NEWS description: #11732: merge with 3.3. diff -r b0890674bc21 -r b87123015fb0 Doc/library/test.rst --- a/Doc/library/test.rst Tue Mar 05 02:28:18 2013 -0800 +++ b/Doc/library/test.rst Tue Mar 05 20:33:38 2013 +0200 @@ -405,6 +405,13 @@ A decorator for running tests that require support for symbolic links. +.. function:: suppress_crash_popup() + + A context manager that disables Windows Error Reporting dialogs using + `SetErrorMode `_. + On other platforms it's a no-op. + + .. decorator:: anticipate_failure(condition) A decorator to conditionally mark tests with diff -r b0890674bc21 -r b87123015fb0 Lib/test/support.py --- a/Lib/test/support.py Tue Mar 05 02:28:18 2013 -0800 +++ b/Lib/test/support.py Tue Mar 05 20:33:38 2013 +0200 @@ -71,7 +71,7 @@ "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 @@ 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 -r b0890674bc21 -r b87123015fb0 Lib/test/test_capi.py --- a/Lib/test/test_capi.py Tue Mar 05 02:28:18 2013 -0800 +++ b/Lib/test/test_capi.py Tue Mar 05 20:33:38 2013 +0200 @@ -44,11 +44,12 @@ @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 -r b0890674bc21 -r b87123015fb0 Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py Tue Mar 05 02:28:18 2013 -0800 +++ b/Lib/test/test_faulthandler.py Tue Mar 05 20:33:38 2013 +0200 @@ -101,7 +101,8 @@ 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._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)) diff -r b0890674bc21 -r b87123015fb0 Misc/NEWS --- a/Misc/NEWS Tue Mar 05 02:28:18 2013 -0800 +++ b/Misc/NEWS Tue Mar 05 20:33:38 2013 +0200 @@ -892,6 +892,10 @@ Tests ----- +- Issue #11732: add a new suppress_crash_popup() context manager to test.support + that disables crash popups on Windows and use it in test_faulthandler and + test_ctypes. + - Issue #13898: test_ssl no longer prints a spurious stack trace on Ubuntu. - Issue #17283: Share code between `__main__.py` and `regrtest.py` in/ezio.melotti@gmail.com