code: def test_nan_error(value, nan_strategy, metric_class):
      """Test correct errors are raised."""
      metric = metric_class(nan_strategy=nan_strategy)
      if nan_strategy == "error":
          with pytest.raises(
              RuntimeError, match="Encountered `nan` values in tensor"
          ):
              metric(value.clone())
      elif nan_strategy == "warn":
          with pytest.warns(
              UserWarning, match="Encountered `nan` values in tensor"
          ):
              metric(value.clone())
  
imports: import numpy
  import pytest
  import torch
  from torchmetrics.aggregation import CatMetric, MaxMetric, MeanMetric, MinMetric, SumMetric
  from torchmetrics.collections import MetricCollection
  from unittests import BATCH_SIZE, NUM_BATCHES
  from unittests.helpers.testers import MetricTester
label_desc: Use image node_id 5 for calling a global function with example usage: test_nan_error(value, nan_strategy, metric_class) without return types