def test_scan_checkpoints(checkpoint_callback_mock, tmp_path, save_top_k: int):
    """Checks if the expected number of checkpoints is returned."""
    # Test first condition of _scan_checkpoints: if c[1] not in logged_model_time.keys()
    # Test if the returned list of checkpoints has length save_top_k
    best_k_models = {}
    for i in range(save_top_k):
        ckpt_path = tmp_path / f"{i}.ckpt"
        with open(ckpt_path, "w") as f:
            f.write("")
        best_k_models[ckpt_path] = i
    checkpoint_callback_mock.best_k_models = best_k_models

    logged_model_time = {}
    checkpoints = _scan_checkpoints(checkpoint_callback_mock, logged_model_time)
    assert len(checkpoints) == save_top_k

    # Test second condition of _scan_checkpoints: or logged_model_time[c[1]] < c[0]]
    # Test if the returned list of checkpoints has still size 0
    for c in checkpoints:
        logged_model_time[c[1]] = c[0] + 1000
    checkpoints = _scan_checkpoints(checkpoint_callback_mock, logged_model_time)
    assert len(checkpoints) == 0
Checks if the expected number of checkpoints is returned.
tests/tests_pytorch/loggers/test_logger.py