def test_invalid_every_n_epochs(tmp_path):
    """Make sure that a MisconfigurationException is raised for a negative every_n_epochs argument."""
    with pytest.raises(MisconfigurationException, match=r".*Must be >= 0"):
        ModelCheckpoint(dirpath=tmp_path, every_n_epochs=-3)
    # These should not fail
    ModelCheckpoint(dirpath=tmp_path, every_n_epochs=0)
    ModelCheckpoint(dirpath=tmp_path, every_n_epochs=1)
    ModelCheckpoint(dirpath=tmp_path, every_n_epochs=2)
Make sure that a MisconfigurationException is raised for a negative every_n_epochs argument.
tests/tests_pytorch/checkpointing/test_model_checkpoint.py