def test_init_optimizers_resets_lightning_optimizers(tmp_path):
    """Test that the Trainer resets the `lightning_optimizers` list everytime new optimizers get initialized."""

    def compare_optimizers():
        assert trainer.strategy._lightning_optimizers[0].optimizer is trainer.optimizers[0]

    model = BoringModel()
    model.lr = 0.2
    trainer = Trainer(default_root_dir=tmp_path, max_epochs=1)
    tuner = Tuner(trainer)

    tuner.lr_find(model)
    compare_optimizers()

    trainer.fit(model)
    compare_optimizers()

    trainer.fit_loop.max_epochs = 2  # simulate multiple fit calls
    trainer.fit(model)
    compare_optimizers()
Test that the Trainer resets the `lightning_optimizers` list everytime new optimizers get initialized.
tests/tests_pytorch/core/test_lightning_optimizer.py