code: def test_caching_actors(shutdown_only, set_enable_auto_connect):
      # Test defining actors before ray.init() has been called.
  
      @ray.remote
      class Foo:
          def __init__(self):
              pass
  
          def get_val(self):
              return 3
  
      if not set_enable_auto_connect:
          # Check that we can't actually create actors before ray.init() has
          # been called.
          with pytest.raises(Exception):
              f = Foo.remote()
  
          ray.init(num_cpus=1)
      else:
          # Actor creation should succeed here because ray.init() auto connection
          # is (by default) enabled.
          f = Foo.remote()
  
      f = Foo.remote()
  
      assert ray.get(f.get_val.remote()) == 3
  
imports: import datetime
  import os
  import random
  import sys
  import tempfile
  import numpy
  import pytest
  import ray
  from ray import cloudpickle
  from ray._private import ray_constants
  from ray._private.test_utils import client_test_enabled, wait_for_condition, wait_for_pid_to_exit
  from ray.actor import ActorClassInheritanceException
  from ray.tests.client_test_utils import create_remote_signal_actor
  from ray._private.test_utils import SignalActor
  import setproctitle
label_desc: Use image node_id 1 for calling a global function with example usage: test_caching_actors(shutdown_only, set_enable_auto_connect) and returns: int