def test_model_checkpoint_to_yaml(tmp_path, save_top_k: int):
    """Test that None in checkpoint callback is valid and that chkp_path is set correctly."""
    model = LogInTwoMethods()

    checkpoint = ModelCheckpoint(dirpath=tmp_path, monitor="early_stop_on", save_top_k=save_top_k)

    trainer = Trainer(default_root_dir=tmp_path, callbacks=[checkpoint], overfit_batches=0.20, max_epochs=2)
    trainer.fit(model)

    path_yaml = tmp_path / "best_k_models.yaml"
    checkpoint.to_yaml(path_yaml)
    with open(path_yaml) as fo:
        d = yaml.full_load(fo)
    best_k = dict(checkpoint.best_k_models.items())
    assert d == best_k
Test that None in checkpoint callback is valid and that chkp_path is set correctly.
tests/tests_pytorch/checkpointing/test_model_checkpoint.py