def test_trainer_error_when_input_not_lightning_module():
    """Test that a useful error gets raised when the Trainer methods receive something other than a LightningModule."""
    trainer = Trainer()

    for method in ("fit", "validate", "test", "predict"):
        with pytest.raises(TypeError, match="must be a `LightningModule`.*got `Linear"):
            run_method = getattr(trainer, method)
            run_method(nn.Linear(2, 2))
Test that a useful error gets raised when the Trainer methods receive something other than a LightningModule.
tests/tests_pytorch/trainer/test_trainer.py