def test_checkpoint_find_last(tmp_path):
    """Test that the last checkpoint is found correctly."""
    model = BoringModel()
    mc = ModelCheckpoint(save_last=True)
    trainer = Trainer(
        max_epochs=1,
        limit_train_batches=1,
        limit_val_batches=0,
        enable_model_summary=False,
        enable_progress_bar=False,
        logger=False,
        default_root_dir=tmp_path,
        callbacks=[mc],
    )
    assert trainer.ckpt_path is None
    trainer.fit(model)

    model = BoringModel()
    mc = ModelCheckpoint()
    trainer = Trainer(
        max_epochs=1,
        limit_train_batches=1,
        limit_val_batches=0,
        enable_model_summary=False,
        enable_progress_bar=False,
        logger=False,
        default_root_dir=tmp_path,
        callbacks=[mc],
    )
    assert trainer.ckpt_path is None
    trainer.fit(model, ckpt_path="last")
    assert trainer.ckpt_path == str(tmp_path / "checkpoints" / "last.ckpt")
Test that the last checkpoint is found correctly.
tests/tests_pytorch/trainer/test_trainer.py