Skip to content

Commit d223fa6

Browse files
committed
Issue #22977: Fix test_exceptions
1 parent 9171fe5 commit d223fa6

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Lib/test/test_exceptions.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from test.support import (TESTFN, captured_output, check_impl_detail,
1212
check_warnings, cpython_only, gc_collect, run_unittest,
13-
no_tracing, unlink, get_attribute)
13+
no_tracing, unlink, import_module)
1414

1515
class NaiveException(Exception):
1616
def __init__(self, x):
@@ -246,12 +246,15 @@ def test_WindowsError(self):
246246
self.assertEqual(w.strerror, 'foo')
247247
self.assertEqual(w.filename, None)
248248

249+
@unittest.skipUnless(sys.platform == 'win32',
250+
'test specific to Windows')
249251
def test_windows_message(self):
250252
"""Should fill in unknown error code in Windows error message"""
251-
windll = get_attribute(ctypes, "windll")
252-
code = int.from_bytes(b"\xE0msc", "big")
253-
with self.assertRaisesRegex(OSError, hex(code)):
254-
windll.kernel32.RaiseException(code, 0, 0, None)
253+
ctypes = import_module('ctypes')
254+
# this error code has no message, Python formats it as hexadecimal
255+
code = 3765269347
256+
with self.assertRaisesRegex(OSError, 'Windows Error 0x%x' % code):
257+
ctypes.pythonapi.PyErr_SetFromWindowsErr(code)
255258

256259
def testAttributes(self):
257260
# test that exception attributes are happy

0 commit comments

Comments
 (0)