def test_early_stopping_no_val_step(tmp_path):
    """Test that early stopping callback falls back to training metrics when no validation defined."""
    model = ClassificationModel()
    dm = ClassifDataModule()
    model.validation_step = None
    model.val_dataloader = None

    stopping = EarlyStopping(monitor="train_loss", min_delta=0.1, patience=0, check_on_train_epoch_end=True)
    trainer = Trainer(default_root_dir=tmp_path, callbacks=[stopping], overfit_batches=0.20, max_epochs=10)
    trainer.fit(model, datamodule=dm)

    assert trainer.state.finished, f"Training failed with {trainer.state}"
    assert trainer.current_epoch < trainer.max_epochs - 1
Test that early stopping callback falls back to training metrics when no validation defined.
tests/tests_pytorch/callbacks/test_early_stopping.py