Skip to content

Commit 2ff3e95

Browse files
[3.13] gh-126742: Avoid checking for library filename in test_ctypes (GH-128034) (#128056)
gh-126742: Avoid checking for library filename in test_ctypes (GH-128034) Avoid checking for library filename in `dlerror()` error messages of test_ctypes. (cherry picked from commit 335e24f) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent f8b4e20 commit 2ff3e95

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

Lib/test/test_ctypes/test_dlerror.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,20 @@ def configure_locales(func):
133133
@classmethod
134134
def setUpClass(cls):
135135
cls.libc_filename = find_library("c")
136+
if cls.libc_filename is None:
137+
raise unittest.SkipTest('cannot find libc')
136138

137139
@configure_locales
138140
def test_localized_error_from_dll(self):
139141
dll = CDLL(self.libc_filename)
140-
with self.assertRaises(AttributeError) as cm:
142+
with self.assertRaises(AttributeError):
141143
dll.this_name_does_not_exist
142-
if sys.platform.startswith('linux'):
143-
# On macOS, the filename is not reported by dlerror().
144-
self.assertIn(self.libc_filename, str(cm.exception))
145144

146145
@configure_locales
147146
def test_localized_error_in_dll(self):
148147
dll = CDLL(self.libc_filename)
149-
with self.assertRaises(ValueError) as cm:
148+
with self.assertRaises(ValueError):
150149
c_int.in_dll(dll, 'this_name_does_not_exist')
151-
if sys.platform.startswith('linux'):
152-
# On macOS, the filename is not reported by dlerror().
153-
self.assertIn(self.libc_filename, str(cm.exception))
154150

155151
@unittest.skipUnless(hasattr(_ctypes, 'dlopen'),
156152
'test requires _ctypes.dlopen()')
@@ -172,11 +168,8 @@ def test_localized_error_dlopen(self):
172168
@configure_locales
173169
def test_localized_error_dlsym(self):
174170
dll = _ctypes.dlopen(self.libc_filename)
175-
with self.assertRaises(OSError) as cm:
171+
with self.assertRaises(OSError):
176172
_ctypes.dlsym(dll, 'this_name_does_not_exist')
177-
if sys.platform.startswith('linux'):
178-
# On macOS, the filename is not reported by dlerror().
179-
self.assertIn(self.libc_filename, str(cm.exception))
180173

181174

182175
if __name__ == "__main__":

0 commit comments

Comments
 (0)