code: def test_disconnect(call_ray_stop_only, set_enable_auto_connect):
      subprocess.check_output(
          "ray start --head --ray-client-server-port=25555", shell=True
      )
      with ray.client("localhost:25555").namespace("n1").connect():
          # Connect via Ray Client
          namespace = ray.get_runtime_context().namespace
          assert namespace == "n1"
          assert ray.util.client.ray.is_connected()
  
      with pytest.raises(ray.exceptions.RaySystemError):
          ray.put(300)
  
      with ray.client(None).namespace("n1").connect():
          # Connect Directly via Driver
          namespace = ray.get_runtime_context().namespace
          assert namespace == "n1"
          assert not ray.util.client.ray.is_connected()
  
      with pytest.raises(ray.exceptions.RaySystemError):
          ray.put(300)
  
      ctx = ray.client("localhost:25555").namespace("n1").connect()
      # Connect via Ray Client
      namespace = ray.get_runtime_context().namespace
      assert namespace == "n1"
      assert ray.util.client.ray.is_connected()
      ctx.disconnect()
      # Check idempotency
      ctx.disconnect()
      with pytest.raises(ray.exceptions.RaySystemError):
          ray.put(300)
  
imports: import os
  import subprocess
  import sys
  import warnings
  from unittest.mock import Mock, patch
  import pytest
  import ray
  import ray.client_builder
  import ray.util.client.server.server
  from ray._private.test_utils import run_string_as_driver, run_string_as_driver_nonblocking, wait_for_condition, skip_flaky_core_test_premerge
  from ray.util.state import list_workers
label_desc: Use image node_id 8 for calling a global function with example usage: test_disconnect(call_ray_stop_only, set_enable_auto_connect) without return types