code: def test_captured_import(start_cluster, tmp_working_dir, option: str):
      """Tests importing a module in the driver and capturing it in a task/actor.
  
      This tests both that this fails *without* the working_dir and that it
      passes with it.
      """
      cluster, address = start_cluster
  
      def call_ray_init():
          if option == "failure":
              # Don't pass the files at all, so it should fail!
              ray.init(address)
          elif option == "working_dir":
              ray.init(
                  address, runtime_env={"working_dir": tmp_working_dir}
              )
          elif option == "py_modules":
              ray.init(
                  address,
                  runtime_env={
                      "py_modules": [
                          os.path.join(tmp_working_dir, "test_module")
                      ]
                  },
              )
  
      call_ray_init()
  
      def reinit():
          ray.shutdown()
          # TODO(SongGuyang): Currently, reinit the driver will generate the same
          # job id. And if we reinit immediately after shutdown, raylet may
          # process new job started before old job finished in some cases. This
          # inconsistency could disorder the URI reference and delete a valid
          # runtime env. We sleep here to walk around this issue.
          time.sleep(5)
          call_ray_init()
  
      # Import in the driver.
      sys.path.insert(0, tmp_working_dir)
      import test_module
  
      @ray.remote
      def test_import():
          return test_module.one()
  
      if option == "failure":
          with pytest.raises(Exception):
              ray.get(test_import.remote())
      else:
          assert ray.get(test_import.remote()) == 1
  
      reinit()
  
      @ray.remote
      class Actor:
          def test_import(self):
              return test_module.one()
  
      if option == "failure":
          with pytest.raises(Exception):
              a = Actor.remote()
              assert ray.get(a.test_import.remote()) == 1
      else:
          a = Actor.remote()
          assert ray.get(a.test_import.remote()) == 1
  
imports: import os
  import shutil
  import sys
  import tempfile
  import time
  from importlib import import_module
  from pathlib import Path
  from unittest import mock
  import pytest
  import ray
  from ray._private import gcs_utils
  from ray._private.runtime_env.context import RuntimeEnvContext
  from ray._private.runtime_env.packaging import get_uri_for_directory, upload_package_if_needed
  from ray._private.runtime_env.working_dir import WorkingDirPlugin, set_pythonpath_in_context
  from ray._private.utils import get_directory_size_bytes
label_desc: Use image node_id 4 for calling a global function with example usage: test_captured_import(start_cluster, tmp_working_dir, option) and returns: test_module, test_module