def test_lightning_hasattr():
    """Test that the lightning_hasattr works in all cases."""
    models, _ = model_and_trainer_cases()
    model1, model2, model3, model4, model5, model6, model7, model8 = models
    assert lightning_hasattr(model1, "learning_rate"), "lightning_hasattr failed to find namespace variable"
    assert lightning_hasattr(model2, "learning_rate"), "lightning_hasattr failed to find hparams namespace variable"
    assert lightning_hasattr(model3, "learning_rate"), "lightning_hasattr failed to find hparams dict variable"
    assert not lightning_hasattr(model4, "learning_rate"), "lightning_hasattr found variable when it should not"
    assert lightning_hasattr(model5, "batch_size"), "lightning_hasattr failed to find batch_size in datamodule"
    assert lightning_hasattr(model6, "batch_size"), (
        "lightning_hasattr failed to find batch_size in datamodule w/ hparams present"
    )
    assert lightning_hasattr(model7, "batch_size"), (
        "lightning_hasattr failed to find batch_size in hparams w/ datamodule present"
    )
    assert lightning_hasattr(model8, "batch_size")

    for m in models:
        assert not lightning_hasattr(m, "this_attr_not_exist")
Test that the lightning_hasattr works in all cases.
tests/tests_pytorch/utilities/test_parsing.py