Skip to content

Commit 80f8bd6

Browse files
committed
Combine nested with statements (ruff SIM117)
1 parent 05cff3f commit 80f8bd6

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

tests/tests_fabric/utilities/test_cloud_io.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)