code: def skip_on_running_out_of_memory(
      reason: str = "Skipping test as it ran out of memory.",
  ):
      """Handle tests that sometimes runs out of memory, by simply skipping them."""
  
      def test_decorator(
          function: Callable, *args: Any, **kwargs: Any
      ) -> Optional[Callable]:
          @wraps(function)
          def run_test(*args: Any, **kwargs: Any) -> Optional[Any]:
              try:
                  return function(*args, **kwargs)
              except RuntimeError as ex:
                  if (
                      "DefaultCPUAllocator: not enough memory:"
                      not in str(ex)
                  ):
                      raise ex
                  pytest.skip(reason)
  
          return run_test
  
      return test_decorator
  
file_path: torchmetrics/tests/unittests/conftest.py
imports: import contextlib
  import os
  import sys
  from functools import wraps
  from typing import Any, Callable, Optional
  import pytest
  import torch
  from torch.multiprocessing import Pool, set_sharing_strategy, set_start_method
label_desc: Use image node_id 4 for calling a global function with example usage: skip_on_running_out_of_memory(reason) and returns: test_decorator, run_test, function