def test_checkpoint_repeated_strategy(tmp_path):
    """This test validates checkpoint can be called several times without increasing internally its global step if
    nothing run."""
    checkpoint_callback = ModelCheckpoint(monitor="val_loss", dirpath=tmp_path, filename="{epoch:02d}")

    class ExtendedBoringModel(BoringModel):
        def validation_step(self, batch, batch_idx):
            loss = self.step(batch)
            self.log("val_loss", loss)

    model = ExtendedBoringModel()
    trainer_kwargs = {
        "max_epochs": 1,
        "limit_train_batches": 2,
        "limit_val_batches": 2,
        "limit_test_batches": 2,
        "enable_progress_bar": False,
        "enable_model_summary": False,
        "log_every_n_steps": 1,
        "default_root_dir": tmp_path,
        "logger": CSVLogger(tmp_path),
    }
    trainer = Trainer(**trainer_kwargs, callbacks=[checkpoint_callback])
    trainer.fit(model)
    assert set(os.listdir(tmp_path)) == {"epoch=00.ckpt", "lightning_logs"}

    for idx in range(4):
        # load from checkpoint
        trainer = Trainer(**trainer_kwargs)
        trainer.fit(model, ckpt_path=checkpoint_callback.best_model_path)
        trainer.test(ckpt_path=checkpoint_callback.best_model_path, verbose=False)

        assert set(os.listdir(tmp_path)) == {"epoch=00.ckpt", "lightning_logs"}

    # no new versions created after the initial fit, because the ones that resume from ckpt do not log anything
    assert set(os.listdir(tmp_path / "lightning_logs")) == {"version_0"}
This test validates checkpoint can be called several times without increasing internally its global step if
    nothing run.
tests/tests_pytorch/checkpointing/test_model_checkpoint.py