def test_fit_val_loop_config(tmp_path):
    """When either val loop or val data are missing raise warning."""
    trainer = Trainer(default_root_dir=tmp_path, max_epochs=1)

    # no val data has val loop
    with pytest.warns(UserWarning, match=r"You passed in a `val_dataloader` but have no `validation_step`"):
        model = BoringModel()
        model.validation_step = None
        trainer.fit(model)

    # has val loop but no val data
    with pytest.warns(PossibleUserWarning, match=r"You defined a `validation_step` but have no `val_dataloader`"):
        model = BoringModel()
        model.val_dataloader = None
        trainer.fit(model)
When either val loop or val data are missing raise warning.
tests/tests_pytorch/trainer/test_config_validator.py