@@ -202,9 +202,11 @@ def test_atomic_save_local_cleans_up_staging_on_failure(tmp_path):
202202 """
203203 filepath = tmp_path / "checkpoint.ckpt"
204204
205- with mock .patch ("lightning.fabric.utilities.cloud_io.os.replace" , side_effect = OSError ("boom" )):
206- with pytest .raises (OSError , match = "boom" ):
207- _atomic_save ({"key" : torch .tensor ([1 , 2 , 3 ])}, filepath )
205+ with (
206+ mock .patch ("lightning.fabric.utilities.cloud_io.os.replace" , side_effect = OSError ("boom" )),
207+ pytest .raises (OSError , match = "boom" ),
208+ ):
209+ _atomic_save ({"key" : torch .tensor ([1 , 2 , 3 ])}, filepath )
208210
209211 assert not filepath .exists ()
210212 assert list (tmp_path .iterdir ()) == [], f"unexpected files left after failed save: { list (tmp_path .iterdir ())} "
@@ -221,9 +223,11 @@ def test_atomic_save_local_preserves_existing_on_failure(tmp_path):
221223 _atomic_save ({"key" : torch .tensor ([0 , 0 , 0 ])}, filepath )
222224 original_bytes = filepath .read_bytes ()
223225
224- with mock .patch ("lightning.fabric.utilities.cloud_io.os.replace" , side_effect = OSError ("boom" )):
225- with pytest .raises (OSError , match = "boom" ):
226- _atomic_save ({"key" : torch .tensor ([42 , 42 , 42 ])}, filepath )
226+ with (
227+ mock .patch ("lightning.fabric.utilities.cloud_io.os.replace" , side_effect = OSError ("boom" )),
228+ pytest .raises (OSError , match = "boom" ),
229+ ):
230+ _atomic_save ({"key" : torch .tensor ([42 , 42 , 42 ])}, filepath )
227231
228232 assert filepath .read_bytes () == original_bytes
229233 assert [p for p in tmp_path .iterdir () if p != filepath ] == []
0 commit comments