code: def test_metriccollection_compute_groups(tmpdir, compute_groups):
      def assertion_calls(keep_base: bool, copy_state: bool):
          if _TORCHMETRICS_GREATER_EQUAL_0_9_1:
              assert copy_state != compute_groups
  
          assert not keep_base
  
      class CustomMetricsCollection(MetricCollection):
          wrapped_assertion_calls = Mock(wraps=assertion_calls)
  
          def items(
              self, keep_base: bool = False, copy_state: bool = True
          ):
              if getattr(self, "_is_currently_logging", False):
                  self.wrapped_assertion_calls(keep_base, copy_state)
  
              return super().items(
                  keep_base=keep_base, copy_state=copy_state
              )
  
      class DummyModule(LightningModule):
          def __init__(self):
              super().__init__()
              if compare_version("torchmetrics", operator.ge, "0.10.0"):
                  from torchmetrics.classification import (
                      MulticlassAccuracy,
                      MulticlassPrecision,
                  )
  
                  metrics = [
                      MulticlassAccuracy(
                          num_classes=10, average="micro"
                      ),
                      MulticlassPrecision(
                          num_classes=10, average="micro"
                      ),
                  ]
              else:
                  from torchmetrics import Accuracy, Precision
  
                  metrics = [
                      Accuracy(num_classes=10, average="micro"),
                      Precision(num_classes=10, average="micro"),
                  ]
  
              self.metrics = CustomMetricsCollection(
                  metrics,
                  compute_groups=compute_groups,
              )
              self.layer = torch.nn.Linear(32, 10)
  
          def training_step(self, batch):
              self.metrics(
                  torch.rand(10, 10).softmax(-1),
                  torch.randint(0, 10, (10,)),
              )
              self.metrics._is_currently_logging = True
              self.log_dict(self.metrics, on_step=True, on_epoch=True)
              self.metrics._is_currently_logging = False
              return self.layer(batch).sum()
  
          def train_dataloader(self):
              return DataLoader(RandomDataset(32, 64))
  
          def configure_optimizers(self):
              return torch.optim.SGD(self.parameters(), lr=0.1)
  
          def on_train_epoch_end(self) -> None:
              self.metrics.wrapped_assertion_calls.call_count == 2
              self.metrics.wrapped_assertion_calls.reset_mock()
  
      trainer = Trainer(
          default_root_dir=tmpdir,
          limit_train_batches=2,
          limit_val_batches=0,
          max_epochs=1,
          enable_progress_bar=False,
          enable_checkpointing=False,
      )
      trainer.fit(DummyModule())
  
imports: import operator
  from functools import partial
  from unittest import mock
  from unittest.mock import Mock
  import pytest
  import torch
  from lightning.pytorch import LightningModule
  from lightning.pytorch.callbacks.callback import Callback
  from lightning.pytorch.demos.boring_classes import BoringModel, RandomDataset
  from lightning.pytorch.loggers import CSVLogger
  from lightning.pytorch.trainer import Trainer
  from lightning.pytorch.trainer.connectors.logger_connector.fx_validator import _FxValidator
  from lightning.pytorch.trainer.connectors.logger_connector.result import _ResultCollection
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.imports import _TORCHMETRICS_GREATER_EQUAL_0_9_1
  from lightning.pytorch.utilities.imports import _TORCHMETRICS_GREATER_EQUAL_0_11
  from lightning_utilities.core.imports import compare_version
  from torch.utils.data import DataLoader
  from torchmetrics import Accuracy, MeanAbsoluteError, MeanSquaredError, MetricCollection
  from torchmetrics import AveragePrecision
  from tests_pytorch.models.test_hooks import get_members
label_desc: Use image node_id 5 for calling a global function with example usage: test_metriccollection_compute_groups(tmpdir, compute_groups) and returns: super, self, DataLoader, torch