code: def test_metric_lightning(tmpdir):
      """Test that including a metric inside a lightning module calculates a simple sum correctly."""
  
      class TestModel(BoringModel):
          def __init__(self) -> None:
              super().__init__()
              self.metric = SumMetric()
              self.register_buffer("sum", torch.tensor(0.0))
  
          def training_step(self, batch, batch_idx):
              x = batch
              self.metric(x.sum())
              self.sum += x.sum()
  
              return self.step(x)
  
          def on_training_epoch_end(self):
              if not torch.allclose(self.sum, self.metric.compute()):
                  raise ValueError(
                      "Sum and computed value must be equal"
                  )
              self.sum = 0.0
              self.metric.reset()
  
      model = TestModel()
      model.val_dataloader = None
  
      trainer = Trainer(
          default_root_dir=tmpdir,
          limit_train_batches=2,
          limit_val_batches=2,
          max_epochs=2,
          log_every_n_steps=1,
      )
      trainer.fit(model)
  
imports: from unittest import mock
  import torch
  from lightning_utilities import module_available
  from torch import tensor
  from torch.nn import Linear
  from torchmetrics import MetricCollection
  from torchmetrics.aggregation import SumMetric
  from torchmetrics.classification import BinaryAccuracy, BinaryAveragePrecision
  from torchmetrics.regression import MeanSquaredError
  from torchmetrics.wrappers import MultitaskWrapper
  from integrations.helpers import no_warning_call
  from integrations.lightning.boring_model import BoringModel
label_desc: Use image node_id 1 for calling a global function with example usage: test_metric_lightning(tmpdir) and returns: self