def test_model_checkpoint_save_last_none_monitor(tmp_path, caplog):
    """Test that it is possible to save all checkpoints when monitor=None."""
    seed_everything()
    model = LogInTwoMethods()

    epochs = 2
    checkpoint_callback = ModelCheckpoint(monitor=None, dirpath=tmp_path, save_top_k=-1, save_last=True)
    trainer = Trainer(
        default_root_dir=tmp_path,
        callbacks=[checkpoint_callback],
        limit_train_batches=10,
        limit_val_batches=10,
        max_epochs=epochs,
        logger=False,
    )
    trainer.fit(model)

    # these should not be set if monitor is None
    assert checkpoint_callback.monitor is None
    assert checkpoint_callback.best_model_path == str(tmp_path / "epoch=1-step=20.ckpt")
    assert checkpoint_callback.last_model_path == str(tmp_path / "last.ckpt")
    assert checkpoint_callback.best_model_score is None
    assert checkpoint_callback.best_k_models == {}
    assert checkpoint_callback.kth_best_model_path == ""

    # check that the correct ckpts were created
    expected = [f"epoch={i}-step={j}.ckpt" for i, j in zip(range(epochs), [10, 20])]
    expected.append("last.ckpt")
    assert set(os.listdir(tmp_path)) == set(expected)
    assert os.path.isfile(tmp_path / "last.ckpt")
Test that it is possible to save all checkpoints when monitor=None.
tests/tests_pytorch/checkpointing/test_model_checkpoint.py