Skip to content

Commit a36e939

Browse files
authored
bpo-30125: disable faulthandler in ctypes test_SEH (#1237)
Disable faulthandler to run test_SEH() of test_ctypes to prevent the following log with a traceback: Windows fatal exception: access violation Add support.disable_faulthandler() context manager.
1 parent ae5b326 commit a36e939

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Lib/ctypes/test/test_win32.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@ class FunctionCallTestCase(unittest.TestCase):
4141
@unittest.skipIf(sys.executable.lower().endswith('_d.exe'),
4242
"SEH not enabled in debug builds")
4343
def test_SEH(self):
44-
# Call functions with invalid arguments, and make sure
45-
# that access violations are trapped and raise an
46-
# exception.
47-
self.assertRaises(OSError, windll.kernel32.GetModuleHandleA, 32)
44+
# Disable faulthandler to prevent logging the warning:
45+
# "Windows fatal exception: access violation"
46+
with support.disable_faulthandler():
47+
# Call functions with invalid arguments, and make sure
48+
# that access violations are trapped and raise an
49+
# exception.
50+
self.assertRaises(OSError, windll.kernel32.GetModuleHandleA, 32)
4851

4952
def test_noargs(self):
5053
# This is a special case on win32 x64
5154
windll.user32.GetDesktopWindow()
5255

56+
5357
@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test')
5458
class TestWintypes(unittest.TestCase):
5559
def test_HWND(self):

Lib/test/support/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,3 +2595,19 @@ def setswitchinterval(interval):
25952595
if _is_android_emulator:
25962596
interval = minimum_interval
25972597
return sys.setswitchinterval(interval)
2598+
2599+
2600+
@contextlib.contextmanager
2601+
def disable_faulthandler():
2602+
# use sys.__stderr__ instead of sys.stderr, since regrtest replaces
2603+
# sys.stderr with a StringIO which has no file descriptor when a test
2604+
# is run with -W/--verbose3.
2605+
fd = sys.__stderr__.fileno()
2606+
2607+
is_enabled = faulthandler.is_enabled()
2608+
try:
2609+
faulthandler.disable()
2610+
yield
2611+
finally:
2612+
if is_enabled:
2613+
faulthandler.enable(file=fd, all_threads=True)

0 commit comments

Comments
 (0)