summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/ctypes/test/test_win32.py12
-rw-r--r--Lib/test/support/__init__.py16
2 files changed, 24 insertions, 4 deletions
diff --git a/Lib/ctypes/test/test_win32.py b/Lib/ctypes/test/test_win32.py
index da1624015e..5d85ad6200 100644
--- a/Lib/ctypes/test/test_win32.py
+++ b/Lib/ctypes/test/test_win32.py
@@ -41,15 +41,19 @@ class FunctionCallTestCase(unittest.TestCase):
@unittest.skipIf(sys.executable.lower().endswith('_d.exe'),
"SEH not enabled in debug builds")
def test_SEH(self):
- # Call functions with invalid arguments, and make sure
- # that access violations are trapped and raise an
- # exception.
- self.assertRaises(OSError, windll.kernel32.GetModuleHandleA, 32)
+ # Disable faulthandler to prevent logging the warning:
+ # "Windows fatal exception: access violation"
+ with support.disable_faulthandler():
+ # Call functions with invalid arguments, and make sure
+ # that access violations are trapped and raise an
+ # exception.
+ self.assertRaises(OSError, windll.kernel32.GetModuleHandleA, 32)
def test_noargs(self):
# This is a special case on win32 x64
windll.user32.GetDesktopWindow()
+
@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test')
class TestWintypes(unittest.TestCase):
def test_HWND(self):
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index d3beef22ae..56b6b07b9b 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2595,3 +2595,19 @@ def setswitchinterval(interval):
if _is_android_emulator:
interval = minimum_interval
return sys.setswitchinterval(interval)
+
+
+@contextlib.contextmanager
+def disable_faulthandler():
+ # use sys.__stderr__ instead of sys.stderr, since regrtest replaces
+ # sys.stderr with a StringIO which has no file descriptor when a test
+ # is run with -W/--verbose3.
+ fd = sys.__stderr__.fileno()
+
+ is_enabled = faulthandler.is_enabled()
+ try:
+ faulthandler.disable()
+ yield
+ finally:
+ if is_enabled:
+ faulthandler.enable(file=fd, all_threads=True)