code: def test_setup_func_failure(shutdown_only):
      """
      Verify when deserilization failed, it raises an exception.
      """
  
      class CustomClass:
          """
          Custom class that can serialize but canont deserialize.
          It is used to test deserialization failure.
          """
  
          def __getstate__(self):
              # This method is called during serialization
              return self.__dict__
  
          def __setstate__(self, state):
              # This method is called during deserialization
              raise RuntimeError("Deserialization not allowed")
  
      c = CustomClass()
  
      def setup():
          print(c)
  
      ray.init(
          num_cpus=1,
          runtime_env={
              "worker_process_setup_hook": setup,
          },
      )
  
      @ray.remote
      class A:
          pass
  
      a = A.remote()
      # TODO(sang): Maybe we should raise RuntimeEnvSetupError?
      # It is pretty difficult now. See
      # https://github.com/ray-project/ray/pull/34738#discussion_r1189553716
      with pytest.raises(ray.exceptions.RayActorError) as e:
          ray.get(a.__ray_ready__.remote())
      assert "Deserialization not allowed" in str(e.value)
  
      """
      Verify when the serialization fails, ray.init fails.
      """
      ray.shutdown()
      lock = threading.Lock()
  
      with pytest.raises(ray.exceptions.RuntimeEnvSetupError) as e:
          ray.init(
              num_cpus=0,
              runtime_env={
                  "worker_process_setup_hook": lambda: print(lock),
              },
          )
      assert "Failed to export the setup function." in str(e.value)
  
      """
      Verify when the setup hook failed, it raises an exception.
      """
      ray.shutdown()
  
      def setup_func():
          raise ValueError("Setup Failed")
  
      ray.init(
          num_cpus=1,
          runtime_env={
              "worker_process_setup_hook": setup_func,
          },
      )
  
      @ray.remote
      class A:
          pass
  
      a = A.remote()
      with pytest.raises(ray.exceptions.RayActorError) as e:
          ray.get(a.__ray_ready__.remote())
      assert "Setup Failed" in str(e.value)
      assert "Failed to execute the setup hook method." in str(e.value)
  
file_path: ray/python/ray/tests/test_runtime_env_setup_func.py
imports: import threading
  import os
  import sys
  import logging
  import tempfile
  import platform
  import pytest
  import ray
  from ray.job_submission import JobSubmissionClient, JobStatus
  from ray._private.test_utils import format_web_url, wait_for_condition
label_desc: Use image node_id 3 for calling a global function with example usage: test_setup_func_failure(shutdown_only) and returns: self