@@ -401,7 +401,7 @@ def test_model_checkpoint_no_extraneous_invocations(tmpdir):
401401 assert trainer .state .finished , f"Training failed with { trainer .state } "
402402
403403
404- def test_model_checkpoint_format_checkpoint_name (tmpdir ):
404+ def test_model_checkpoint_format_checkpoint_name (tmpdir , monkeypatch ):
405405 # empty filename:
406406 ckpt_name = ModelCheckpoint ._format_checkpoint_name ("" , {"epoch" : 3 , "step" : 2 })
407407 assert ckpt_name == "epoch=3-step=2"
@@ -422,18 +422,16 @@ def test_model_checkpoint_format_checkpoint_name(tmpdir):
422422 assert ckpt_name == "epoch=003-epoch_test=003"
423423
424424 # prefix
425- char_org = ModelCheckpoint .CHECKPOINT_JOIN_CHAR
426- ModelCheckpoint .CHECKPOINT_JOIN_CHAR = "@"
425+ monkeypatch .setattr (ModelCheckpoint , "CHECKPOINT_JOIN_CHAR" , "@" )
427426 ckpt_name = ModelCheckpoint ._format_checkpoint_name ("{epoch},{acc:.5f}" , {"epoch" : 3 , "acc" : 0.03 }, prefix = "test" )
428427 assert ckpt_name == "test@epoch=3,acc=0.03000"
429- ModelCheckpoint . CHECKPOINT_JOIN_CHAR = char_org
428+ monkeypatch . undo ()
430429
431430 # non-default char for equals sign
432- default_char = ModelCheckpoint .CHECKPOINT_EQUALS_CHAR
433- ModelCheckpoint .CHECKPOINT_EQUALS_CHAR = ":"
431+ monkeypatch .setattr (ModelCheckpoint , "CHECKPOINT_EQUALS_CHAR" , ":" )
434432 ckpt_name = ModelCheckpoint ._format_checkpoint_name ("{epoch:03d}-{acc}" , {"epoch" : 3 , "acc" : 0.03 })
435433 assert ckpt_name == "epoch:003-acc:0.03"
436- ModelCheckpoint . CHECKPOINT_EQUALS_CHAR = default_char
434+ monkeypatch . undo ()
437435
438436 # no dirpath set
439437 ckpt_name = ModelCheckpoint (monitor = "early_stop_on" , dirpath = None ).format_checkpoint_name ({"epoch" : 3 , "step" : 2 })
0 commit comments