code: def test_metric_collection(tmpdir):
      """Test that updating the metric collection is equal to individually updating metrics in the collection."""
      m1 = DummyMetricSum()
      m2 = DummyMetricDiff()
  
      metric_collection = MetricCollection([m1, m2])
  
      # Test correct dict structure
      assert len(metric_collection) == 2
      assert metric_collection["DummyMetricSum"] == m1
      assert metric_collection["DummyMetricDiff"] == m2
  
      # Test correct initialization
      for name, metric in metric_collection.items():
          assert (
              metric.x == 0
          ), f"Metric {name} not initialized correctly"
  
      # Test every metric gets updated
      metric_collection.update(5)
      for name, metric in metric_collection.items():
          assert (
              metric.x.abs() == 5
          ), f"Metric {name} not updated correctly"
  
      # Test compute on each metric
      metric_collection.update(-5)
      metric_vals = metric_collection.compute()
      assert len(metric_vals) == 2
      for name, metric_val in metric_vals.items():
          assert (
              metric_val == 0
          ), f"Metric {name}.compute not called correctly"
  
      # Test that everything is reset
      for name, metric in metric_collection.items():
          assert metric.x == 0, f"Metric {name} not reset correctly"
  
      # Test pickable
      metric_pickled = pickle.dumps(metric_collection)
      metric_loaded = pickle.loads(metric_pickled)
      assert isinstance(metric_loaded, MetricCollection)
  
imports: import pickle
  from copy import deepcopy
  from typing import Any
  import pytest
  import torch
  from torchmetrics import Metric, MetricCollection
  from torchmetrics.classification import BinaryAccuracy, MulticlassAccuracy, MulticlassAUROC, MulticlassAveragePrecision, MulticlassCohenKappa, MulticlassConfusionMatrix, MulticlassF1Score, MulticlassMatthewsCorrCoef, MulticlassPrecision, MulticlassRecall, MultilabelAUROC, MultilabelAveragePrecision
  from torchmetrics.utilities.checks import _allclose_recursive
  from unittests.helpers import seed_all
  from unittests.helpers.testers import DummyMetricDiff, DummyMetricMultiOutputDict, DummyMetricSum
label_desc: Use image node_id 1 for calling a global function with example usage: test_metric_collection(tmpdir) without return types