@@ -147,20 +147,22 @@ def test_localized_error_from_dll(self):
147147 with tempfile .TemporaryDirectory () as outdir :
148148 dstname = self .make_empty_lib (outdir , 'test_from_dll.so' )
149149 dll = CDLL (dstname )
150- # on macOS, the filename is not reported by dlerror()
151- pat = '.+' if sys .platform == 'darwin' else r'test_from_dll\.so'
152- with self .assertRaisesRegex (AttributeError , pat ):
150+ with self .assertRaises (AttributeError ) as cm :
153151 dll .foo
152+ if sys .platform .startswith ('linux' ):
153+ # On macOS or Windows, the filename is not reported by dlerror()
154+ self .assertIn ('test_from_dll.so' , str (cm .exception ))
154155
155156 @configure_locales
156157 def test_localized_error_in_dll (self ):
157158 with tempfile .TemporaryDirectory () as outdir :
158159 dstname = self .make_empty_lib (outdir , 'test_in_dll.so' )
159160 dll = CDLL (dstname )
160- # on macOS, the filename is not reported by dlerror()
161- pat = '.+' if sys .platform == 'darwin' else r'test_in_dll\.so'
162- with self .assertRaisesRegex (ValueError , pat ):
161+ with self .assertRaises (ValueError ) as cm :
163162 c_int .in_dll (dll , 'foo' )
163+ if sys .platform .startswith ('linux' ):
164+ # On macOS or Windows, the filename is not reported by dlerror()
165+ self .assertIn ('test_in_dll.so' , str (cm .exception ))
164166
165167 @unittest .skipUnless (hasattr (_ctypes , 'dlopen' ),
166168 'test requires _ctypes.dlopen()' )
@@ -184,10 +186,11 @@ def test_localized_error_dlsym(self):
184186 with tempfile .TemporaryDirectory () as outdir :
185187 dstname = self .make_empty_lib (outdir , 'test_dlsym.so' )
186188 dll = _ctypes .dlopen (dstname )
187- # on macOS, the filename is not reported by dlerror()
188- pat = '.+' if sys .platform == 'darwin' else r'test_dlsym\.so'
189- with self .assertRaisesRegex (OSError , pat ):
189+ with self .assertRaises (OSError ) as cm :
190190 _ctypes .dlsym (dll , 'foo' )
191+ if sys .platform .startswith ('linux' ):
192+ # On macOS or Windows, the filename is not reported by dlerror()
193+ self .assertIn ('test_in_dll.so' , str (cm .exception ))
191194
192195
193196if __name__ == "__main__" :
0 commit comments