@@ -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
@@ -781,7 +787,10 @@ def verify_equal_length_columns(self, ts, table):
781787 data = dict (all_data )
782788 data [col ] = bad_val
783789 kastore .dump (data , self .temp_file )
784- with pytest .raises (exceptions .FileFormatError ):
790+ with pytest .raises (
791+ exceptions .FileFormatError ,
792+ match = f"While trying to load { self .temp_file } " ,
793+ ):
785794 tskit .load (self .temp_file )
786795
787796 def test_equal_length_columns (self ):
@@ -805,7 +814,10 @@ def verify_offset_columns(self, ts):
805814 for bad_col_length in [[], range (2 * num_rows )]:
806815 data [offset_col ] = bad_col_length
807816 kastore .dump (data , self .temp_file )
808- with pytest .raises (exceptions .FileFormatError ):
817+ with pytest .raises (
818+ exceptions .FileFormatError ,
819+ match = f"While trying to load { self .temp_file } " ,
820+ ):
809821 tskit .load (self .temp_file )
810822
811823 # Check for a bad offset
@@ -853,13 +865,17 @@ def test_index_columns(self):
853865 data = dict (all_data )
854866 data [edge_insertion_order ] = data [edge_insertion_order ][:1 ]
855867 kastore .dump (data , self .temp_file )
856- with pytest .raises (exceptions .FileFormatError ):
868+ with pytest .raises (
869+ exceptions .FileFormatError , match = f"While trying to load { self .temp_file } "
870+ ):
857871 tskit .load (self .temp_file )
858872
859873 data = dict (all_data )
860874 data [edge_removal_order ] = data [edge_removal_order ][:1 ]
861875 kastore .dump (data , self .temp_file )
862- with pytest .raises (exceptions .FileFormatError ):
876+ with pytest .raises (
877+ exceptions .FileFormatError , match = f"While trying to load { self .temp_file } "
878+ ):
863879 tskit .load (self .temp_file )
864880
865881 def test_load_empty_kastore (self ):
@@ -897,7 +913,10 @@ def test_format_name_error(self):
897913 data = dict (store )
898914 data ["format/name" ] = np .array (bytearray (bad_name .encode ()), dtype = np .int8 )
899915 kastore .dump (data , self .temp_file )
900- with pytest .raises (exceptions .FileFormatError ):
916+ with pytest .raises (
917+ exceptions .FileFormatError ,
918+ match = f"While trying to load { self .temp_file } " ,
919+ ):
901920 tskit .load (self .temp_file )
902921
903922 def test_load_bad_formats (self ):
@@ -908,12 +927,16 @@ def test_load_bad_formats(self):
908927 # Now some ascii text
909928 with open (self .temp_file , "wb" ) as f :
910929 f .write (b"Some ASCII text" )
911- with pytest .raises (exceptions .FileFormatError ):
930+ with pytest .raises (
931+ exceptions .FileFormatError , match = f"While trying to load { self .temp_file } "
932+ ):
912933 tskit .load (self .temp_file )
913934 # Now write 8k of random bytes
914935 with open (self .temp_file , "wb" ) as f :
915936 f .write (os .urandom (8192 ))
916- with pytest .raises (exceptions .FileFormatError ):
937+ with pytest .raises (
938+ exceptions .FileFormatError , match = f"While trying to load { self .temp_file } "
939+ ):
917940 tskit .load (self .temp_file )
918941
919942 def test_load_bad_formats_fileobj (self ):
@@ -925,7 +948,9 @@ def load():
925948 load ()
926949 with open (self .temp_file , "wb" ) as f :
927950 f .write (b"Some ASCII text" )
928- with pytest .raises (exceptions .FileFormatError ):
951+ with pytest .raises (
952+ exceptions .FileFormatError , match = f"While trying to load { self .temp_file } "
953+ ):
929954 load ()
930955
931956
@@ -978,7 +1003,9 @@ def test_ts_twofile_stream_fails(self, tmp_path, ts_fixture):
9781003 ts_fixture .dump (f )
9791004 with open (save_path , "rb" ) as f :
9801005 tskit .load (f , skip_tables = True )
981- with pytest .raises (exceptions .FileFormatError ):
1006+ with pytest .raises (
1007+ exceptions .FileFormatError , match = f"While trying to load { save_path } "
1008+ ):
9821009 tskit .load (f )
9831010
9841011 def test_table_collection_load_path (self , tmp_path , ts_fixture ):
@@ -1033,7 +1060,9 @@ def test_ts_twofile_stream_fails(self, tmp_path, ts_fixture):
10331060 ts_fixture .dump (f )
10341061 with open (save_path , "rb" ) as f :
10351062 tskit .load (f , skip_reference_sequence = True )
1036- with pytest .raises (exceptions .FileFormatError ):
1063+ with pytest .raises (
1064+ exceptions .FileFormatError , match = f"While trying to load { save_path } "
1065+ ):
10371066 tskit .load (f )
10381067
10391068 def test_table_collection_load_path (self , tmp_path , ts_fixture ):
0 commit comments