def test_ckpt_version_counter_disabled_after_rerun_new_trainer(tmp_path):
    """Check that previous checkpoints get overwritten and no suffixes are generated when new trainer instances are
    used."""
    epochs = 2
    for i in range(epochs):
        mc = ModelCheckpoint(
            dirpath=tmp_path,
            save_top_k=-1,
            save_last=True,
            monitor="epoch",
            filename="{epoch}",
            enable_version_counter=False,
        )
        trainer = Trainer(
            max_epochs=epochs,
            limit_train_batches=1,
            limit_val_batches=1,
            default_root_dir=tmp_path,
            callbacks=[mc],
            logger=False,
            enable_progress_bar=False,
            enable_model_summary=False,
        )
        trainer.fit(BoringModel())

        # check best_k_models and last state
        assert {Path(f).name for f in mc.best_k_models} == {"epoch=0.ckpt", "epoch=1.ckpt"}
        assert Path(mc.last_model_path).name == "last.ckpt"

    # check created ckpts
    actual = {f.name for f in tmp_path.iterdir()}
    assert actual == {"epoch=0.ckpt", "epoch=1.ckpt", "last.ckpt"}
Check that previous checkpoints get overwritten and no suffixes are generated when new trainer instances are
    used.
tests/tests_pytorch/checkpointing/test_model_checkpoint.py