code: def test_lazy_reads(
      insert_test_dir_in_pythonpath,
      start_cluster,
      tmp_working_dir,
      option: str,
  ):
      """Tests the case where we lazily read files or import inside a task/actor.
  
      This tests both that this fails *without* the working_dir and that it
      passes with it.  Also tests that the existing PYTHONPATH is preserved,
      so packages preinstalled on the cluster are still importable when using
      py_modules or working_dir.
      """
      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 == "working_dir_zip":
              # Create a temp dir to place the zipped package
              # from tmp_working_dir
              with tempfile.TemporaryDirectory() as tmp_dir:
                  zip_dir = Path(tmp_working_dir)
                  package = shutil.make_archive(
                      os.path.join(tmp_dir, "test"), "zip", zip_dir
                  )
                  ray.init(
                      address, runtime_env={"working_dir": package}
                  )
          elif option == "py_modules":
              ray.init(
                  address,
                  runtime_env={
                      "py_modules": [
                          str(Path(tmp_working_dir) / "test_module"),
                          Path(os.path.dirname(__file__))
                          / "pip_install_test-0.5-py3-none-any.whl",
                      ]
                  },
              )
          elif option == "working_dir_and_py_modules":
              ray.init(
                  address,
                  runtime_env={
                      "working_dir": tmp_working_dir,
                      "py_modules": [
                          str(Path(tmp_working_dir) / "test_module"),
                          Path(os.path.dirname(__file__))
                          / "pip_install_test-0.5-py3-none-any.whl",
                      ],
                  },
              )
          else:
              raise ValueError(f"unexpected pytest parameter {option}")
  
      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()
  
      @ray.remote
      def test_import():
          import test_module
  
          assert TEST_IMPORT_DIR in os.environ.get("PYTHONPATH", "")
          return test_module.one()
  
      if option == "failure":
          with pytest.raises(ImportError):
              ray.get(test_import.remote())
      else:
          assert ray.get(test_import.remote()) == 1
  
      if option in {"py_modules", "working_dir_and_py_modules"}:
  
          @ray.remote
          def test_py_modules_whl():
              import pip_install_test  # noqa: F401
  
              return True
  
          assert ray.get(test_py_modules_whl.remote())
  
      if option in {"py_modules", "working_dir_zip"}:
          # These options are not tested beyond this point, so return to save time.
          return
  
      reinit()
  
      @ray.remote
      def test_read():
          return open("hello").read()
  
      if option == "failure":
          with pytest.raises(FileNotFoundError):
              ray.get(test_read.remote())
      elif option in {"working_dir_and_py_modules", "working_dir"}:
          assert ray.get(test_read.remote()) == "world"
  
      reinit()
  
      @ray.remote
      class Actor:
          def test_import(self):
              import test_module
  
              assert TEST_IMPORT_DIR in os.environ.get("PYTHONPATH", "")
              return test_module.one()
  
          def test_read(self):
              assert TEST_IMPORT_DIR in os.environ.get("PYTHONPATH", "")
              return open("hello").read()
  
      a = Actor.remote()
      if option == "failure":
          with pytest.raises(ImportError):
              assert ray.get(a.test_import.remote()) == 1
          with pytest.raises(FileNotFoundError):
              assert ray.get(a.test_read.remote()) == "world"
      elif option in {"working_dir_and_py_modules", "working_dir"}:
          assert ray.get(a.test_import.remote()) == 1
          assert ray.get(a.test_read.remote()) == "world"
  
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 3 for calling a global function with example usage: test_lazy_reads(insert_test_dir_in_pythonpath, start_cluster, tmp_working_dir, option) and returns: test_module, open, True, test_module, open