@@ -261,12 +261,12 @@ def test_format_too_old_raised_for_hdf5(self):
261261
262262 with pytest .raises (
263263 exceptions .FileFormatError ,
264- match = " appears to be in HDF5 format" ,
264+ match = f" { filename } .* appears to be in HDF5 format" ,
265265 ):
266266 tskit .load (path )
267267 with pytest .raises (
268268 exceptions .FileFormatError ,
269- match = " appears to be in HDF5 format" ,
269+ match = f" { filename } .* appears to be in HDF5 format" ,
270270 ):
271271 tskit .TableCollection .load (path )
272272
@@ -284,9 +284,15 @@ class TestErrors(TestFileFormat):
284284 def test_tszip_file (self ):
285285 ts = msprime .simulate (5 )
286286 tszip .compress (ts , self .temp_file )
287- with pytest .raises (tskit .FileFormatError , match = "appears to be in zip format" ):
287+ with pytest .raises (
288+ tskit .FileFormatError ,
289+ match = f"{ self .temp_file } .*appears to be in zip format" ,
290+ ):
288291 tskit .load (self .temp_file )
289- with pytest .raises (tskit .FileFormatError , match = "appears to be in zip format" ):
292+ with pytest .raises (
293+ tskit .FileFormatError ,
294+ match = f"{ self .temp_file } .*appears to be in zip format" ,
295+ ):
290296 tskit .TableCollection .load (self .temp_file )
291297
292298
@@ -897,7 +903,10 @@ def test_format_name_error(self):
897903 data = dict (store )
898904 data ["format/name" ] = np .array (bytearray (bad_name .encode ()), dtype = np .int8 )
899905 kastore .dump (data , self .temp_file )
900- with pytest .raises (exceptions .FileFormatError ):
906+ with pytest .raises (
907+ exceptions .FileFormatError ,
908+ match = f"While trying to load { self .temp_file } " ,
909+ ):
901910 tskit .load (self .temp_file )
902911
903912 def test_load_bad_formats (self ):
@@ -908,12 +917,16 @@ def test_load_bad_formats(self):
908917 # Now some ascii text
909918 with open (self .temp_file , "wb" ) as f :
910919 f .write (b"Some ASCII text" )
911- with pytest .raises (exceptions .FileFormatError ):
920+ with pytest .raises (
921+ exceptions .FileFormatError , match = f"While trying to load { self .temp_file } "
922+ ):
912923 tskit .load (self .temp_file )
913924 # Now write 8k of random bytes
914925 with open (self .temp_file , "wb" ) as f :
915926 f .write (os .urandom (8192 ))
916- with pytest .raises (exceptions .FileFormatError ):
927+ with pytest .raises (
928+ exceptions .FileFormatError , match = f"While trying to load { self .temp_file } "
929+ ):
917930 tskit .load (self .temp_file )
918931
919932 def test_load_bad_formats_fileobj (self ):
@@ -925,7 +938,9 @@ def load():
925938 load ()
926939 with open (self .temp_file , "wb" ) as f :
927940 f .write (b"Some ASCII text" )
928- with pytest .raises (exceptions .FileFormatError ):
941+ with pytest .raises (
942+ exceptions .FileFormatError , match = f"While trying to load { self .temp_file } "
943+ ):
929944 load ()
930945
931946
0 commit comments