code: def testAddShouldUseExceptionInEagerAndFunction(self):
      def in_this_function():
          c = constant_op.constant(0, name="blah0")
          h = tf_should_use._add_should_use_warning(
              c, warn_in_eager=True, error_in_function=True
          )
          del h
  
      if context.executing_eagerly():
          with reroute_error() as error:
              in_this_function()
          msg = "\n".join(error.call_args[0])
          self.assertIn("Object was never used", msg)
          self.assertIn("in_this_function", msg)
          self.assertFalse(gc.garbage)
  
      tf_fn_in_this_function = def_function.function(in_this_function)
      with self.assertRaisesRegex(
          RuntimeError, r"Object was never used.*blah0:0"
      ):
          tf_fn_in_this_function()
      self.assertFalse(gc.garbage)
  
imports: import contextlib
  import gc
  import sys
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import test_util
  from tensorflow.python.platform import test
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.util import tf_should_use
label_desc: Use image node_id 2 for calling the TfShouldUseTest obj's underlying member method code with example usage: obj.testAddShouldUseExceptionInEagerAndFunction() without return types