def test_none_monitor_top_k(tmp_path):
    """Test that a warning appears for positive top_k with monitor=None."""
    with pytest.raises(
        MisconfigurationException, match=r"ModelCheckpoint\(save_top_k=3, monitor=None\) is not a valid*"
    ):
        ModelCheckpoint(dirpath=tmp_path, save_top_k=3)
    # These should not fail
    ModelCheckpoint(dirpath=tmp_path, save_top_k=-1)
    ModelCheckpoint(dirpath=tmp_path, save_top_k=0)
    ModelCheckpoint(dirpath=tmp_path, save_top_k=1)
Test that a warning appears for positive top_k with monitor=None.
tests/tests_pytorch/checkpointing/test_model_checkpoint.py