Skip to content

Commit a49b1c8

Browse files
awaelchlilantiga
authored andcommitted
Fix ModelCheckpoint.CHECKPOINT_NAME_LAST test interaction (#18993)
(cherry picked from commit b4605b4)
1 parent d947b01 commit a49b1c8

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tests/tests_pytorch/checkpointing/test_model_checkpoint.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,12 @@ def test_model_checkpoint_file_extension(tmpdir):
485485
assert set(expected) == set(os.listdir(tmpdir))
486486

487487

488-
def test_model_checkpoint_save_last(tmpdir):
488+
def test_model_checkpoint_save_last(tmpdir, monkeypatch):
489489
"""Tests that save_last produces only one last checkpoint."""
490490
seed_everything()
491491
model = LogInTwoMethods()
492492
epochs = 3
493-
ModelCheckpoint.CHECKPOINT_NAME_LAST = "last-{epoch}"
493+
monkeypatch.setattr(ModelCheckpoint, "CHECKPOINT_NAME_LAST", "last-{epoch}")
494494
model_checkpoint = ModelCheckpoint(monitor="early_stop_on", dirpath=tmpdir, save_top_k=-1, save_last=True)
495495
trainer = Trainer(
496496
default_root_dir=tmpdir,
@@ -511,7 +511,6 @@ def test_model_checkpoint_save_last(tmpdir):
511511
)
512512
assert os.path.islink(tmpdir / last_filename)
513513
assert os.path.realpath(tmpdir / last_filename) == model_checkpoint._last_checkpoint_saved
514-
ModelCheckpoint.CHECKPOINT_NAME_LAST = "last"
515514

516515

517516
def test_model_checkpoint_link_checkpoint(tmp_path):

0 commit comments

Comments
 (0)