code: def test_with_ray_init(shutdown_only):
      @ray.remote
      def f():
          return 42
  
      with ray.init() as ctx:
          assert ray.is_initialized()
          assert 42 == ray.get(f.remote())
          # Check old context fields can be accessed like a dict
          assert ctx["session_dir"] is not None
          assert ctx["node_id"] is not None
          with pytest.raises(KeyError):
              ctx["xyz"]
          # Check that __contains__ works
          assert "session_dir" in ctx
          assert "abcdefg" not in ctx
          # Check that get works
          assert ctx.get("session_dir") is not None
          assert ctx.get("gfedcba") is None
      assert not ray.is_initialized()
  
imports: import logging
  import os
  import sys
  import unittest.mock
  import tempfile
  import shutil
  from unittest.mock import patch
  import pytest
  import ray
  from ray._private.ray_constants import RAY_OVERRIDE_DASHBOARD_URL, DEFAULT_RESOURCES
  from ray.air.util.node import _get_node_id_from_node_ip
  import ray._private.services
  from ray._private.services import get_node_ip_address
  from ray.dashboard.utils import ray_address_to_api_server_url
  from ray._private.test_utils import get_current_unused_port, run_string_as_driver, wait_for_condition
  from ray.util.client.ray_client_helpers import ray_start_client_server
label_desc: Use image node_id 2 for calling a global function with example usage: test_with_ray_init(shutdown_only) and returns: int