code: def set_env_var(key: str, val: Optional[str] = None):
      old_val = os.environ.get(key, None)
      if val is not None:
          os.environ[key] = val
      elif key in os.environ:
          del os.environ[key]
  
      try:
          yield
      finally:
          if key in os.environ:
              del os.environ[key]
          if old_val is not None:
              os.environ[key] = old_val
  
imports: from contextlib import contextmanager
  import ray
  import json
  import os
  import logging
  import sys
  import subprocess
  from typing import Optional, Tuple
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: set_env_var(key, val) without return types