mirror of
https://github.com/python/cpython.git
synced 2025-09-30 20:31:52 +00:00
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.
(cherry picked from commit a36e939aeb
)
This commit is contained in:
parent
cb21f5f3d2
commit
e005dd9a6d
2 changed files with 24 additions and 4 deletions
|
@ -41,15 +41,19 @@ class FunctionCallTestCase(unittest.TestCase):
|
||||||
@unittest.skipIf(sys.executable.lower().endswith('_d.exe'),
|
@unittest.skipIf(sys.executable.lower().endswith('_d.exe'),
|
||||||
"SEH not enabled in debug builds")
|
"SEH not enabled in debug builds")
|
||||||
def test_SEH(self):
|
def test_SEH(self):
|
||||||
# Call functions with invalid arguments, and make sure
|
# Disable faulthandler to prevent logging the warning:
|
||||||
# that access violations are trapped and raise an
|
# "Windows fatal exception: access violation"
|
||||||
# exception.
|
with support.disable_faulthandler():
|
||||||
self.assertRaises(OSError, windll.kernel32.GetModuleHandleA, 32)
|
# 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):
|
def test_noargs(self):
|
||||||
# This is a special case on win32 x64
|
# This is a special case on win32 x64
|
||||||
windll.user32.GetDesktopWindow()
|
windll.user32.GetDesktopWindow()
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test')
|
@unittest.skipUnless(sys.platform == "win32", 'Windows-specific test')
|
||||||
class TestWintypes(unittest.TestCase):
|
class TestWintypes(unittest.TestCase):
|
||||||
def test_HWND(self):
|
def test_HWND(self):
|
||||||
|
|
|
@ -2586,3 +2586,19 @@ def setswitchinterval(interval):
|
||||||
if _is_android_emulator:
|
if _is_android_emulator:
|
||||||
interval = minimum_interval
|
interval = minimum_interval
|
||||||
return sys.setswitchinterval(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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue