code: def testPrepareSessionFails(self):
      checkpoint_dir = os.path.join(
          self.get_temp_dir(), "prepare_session"
      )
      checkpoint_dir2 = os.path.join(
          self.get_temp_dir(), "prepare_session2"
      )
      try:
          gfile.DeleteRecursively(checkpoint_dir)
          gfile.DeleteRecursively(checkpoint_dir2)
      except errors.OpError:
          pass  # Ignore
      gfile.MakeDirs(checkpoint_dir)
  
      with ops.Graph().as_default():
          v = variable_v1.VariableV1([1.0, 2.0, 3.0], name="v")
          sm = session_manager.SessionManager(
              ready_op=variables.report_uninitialized_variables()
          )
          saver = saver_lib.Saver({"v": v})
          sess = sm.prepare_session(
              "",
              init_op=variables.global_variables_initializer(),
              saver=saver,
              checkpoint_dir=checkpoint_dir,
          )
          self.assertAllClose([1.0, 2.0, 3.0], sess.run(v))
          checkpoint_filename = os.path.join(
              checkpoint_dir, "prepare_session_checkpoint"
          )
          saver.save(sess, checkpoint_filename)
      # Create a new Graph and SessionManager and recover.
      with ops.Graph().as_default():
          # Renames the checkpoint directory.
          os.rename(checkpoint_dir, checkpoint_dir2)
          gfile.MakeDirs(checkpoint_dir)
          v = variable_v1.VariableV1([6.0, 7.0, 8.0], name="v")
          with self.cached_session():
              self.assertEqual(
                  False, variable_v1.is_variable_initialized(v).eval()
              )
          session_manager.SessionManager(
              ready_op=variables.report_uninitialized_variables()
          )
          saver = saver_lib.Saver({"v": v})
          # This should fail as there's no checkpoint within 2 seconds.
          with self.assertRaisesRegex(
              RuntimeError,
              "no init_op or init_fn or local_init_op was given",
          ):
              sess = sm.prepare_session(
                  "",
                  init_op=None,
                  saver=saver,
                  checkpoint_dir=checkpoint_dir,
                  wait_for_checkpoint=True,
                  max_wait_secs=2,
              )
          # Rename the checkpoint directory back.
          gfile.DeleteRecursively(checkpoint_dir)
          os.rename(checkpoint_dir2, checkpoint_dir)
          # This should succeed as there's checkpoint.
          sess = sm.prepare_session(
              "",
              init_op=None,
              saver=saver,
              checkpoint_dir=checkpoint_dir,
              wait_for_checkpoint=True,
              max_wait_secs=2,
          )
          self.assertEqual(
              True,
              variable_v1.is_variable_initialized(
                  sess.graph.get_tensor_by_name("v:0")
              ).eval(session=sess),
          )
  
imports: import os
  from tensorflow.python.checkpoint import checkpoint_management
  from tensorflow.python.client import session
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import errors_impl
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import resource_variables_toggle
  from tensorflow.python.ops import variable_v1
  from tensorflow.python.ops import variables
  from tensorflow.python.ops import while_loop
  from tensorflow.python.platform import gfile
  from tensorflow.python.platform import test
  from tensorflow.python.training import saver
  from tensorflow.python.training import server_lib
  from tensorflow.python.training import session_manager
label_desc: Use image node_id 6 for calling the SessionManagerTest obj's underlying member method code with example usage: obj.testPrepareSessionFails() without return types