code: def restore_env_variables():
      """Ensures that environment variables set during the test do not leak out."""
      env_backup = os.environ.copy()
      yield
      leaked_vars = os.environ.keys() - env_backup.keys()
      # restore environment as it was before running the test
      os.environ.clear()
      os.environ.update(env_backup)
      # these are currently known leakers - ideally these would not be allowed
      # TODO(fabric): this list can be trimmed, maybe PL's too after moving tests
      allowlist = {
          "CUDA_DEVICE_ORDER",
          "LOCAL_RANK",
          "NODE_RANK",
          "WORLD_SIZE",
          "MASTER_ADDR",
          "MASTER_PORT",
          "PL_GLOBAL_SEED",
          "PL_SEED_WORKERS",
          "RANK",  # set by DeepSpeed
          "POPLAR_ENGINE_OPTIONS",  # set by IPUStrategy
          "CUDA_MODULE_LOADING",  # leaked since PyTorch 1.13
          "CRC32C_SW_MODE",  # set by tensorboardX
          "OMP_NUM_THREADS",  # set by our launchers
          # set by torchdynamo
          "TRITON_CACHE_DIR",
      }
      leaked_vars.difference_update(allowlist)
      assert (
          not leaked_vars
      ), f"test is leaking environment variable(s): {set(leaked_vars)}"
  
imports: import os
  import sys
  import threading
  from typing import List
  from unittest.mock import Mock
  import lightning.fabric
  import pytest
  import torch.distributed
  from lightning.fabric.accelerators import XLAAccelerator
  from lightning.fabric.strategies.launchers.subprocess_script import _ChildProcessObserver
  from lightning.fabric.utilities.distributed import _distributed_is_initialized
label_desc: Use image node_id 2 for calling a global function with example usage: restore_env_variables() without return types