code: def test_lightning_optimizer_keeps_hooks():
      model = BoringModel()
      optimizer = OptimizerWithHooks(model)
      lightning_optimizer = LightningOptimizer(optimizer)
      assert len(optimizer._fwd_handles) == 1
      del lightning_optimizer
      assert len(optimizer._fwd_handles) == 1
  
imports: from copy import deepcopy
  from unittest.mock import DEFAULT, Mock, patch
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.core.optimizer import LightningOptimizer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loops.optimization.automatic import Closure
  from lightning.pytorch.tuner.tuning import Tuner
  from torch.optim import SGD, Adam, Optimizer
label_desc: Use image node_id 9 for calling a global function with example usage: test_lightning_optimizer_keeps_hooks() without return types