code: def test_log_file_writer_as_context_manager_with_exception(ex, tf):
      """
      Check that Tensorflow log directory is captured by LogFileWriter context manager.
      """
      TEST_LOG_DIR = "/tmp/sacred_test"
  
      @ex.main
      def run_experiment(_run):
          assert _run.info.get("tensorflow", None) is None
          with tf.Session() as s:
              # Capturing the log directory should be done only in scope of the context manager
              try:
                  with LogFileWriter(ex):
                      swr = tf.summary.FileWriter(
                          logdir=TEST_LOG_DIR, graph=s.graph
                      )
                      assert swr is not None
                      assert _run.info["tensorflow"]["logdirs"] == [
                          TEST_LOG_DIR
                      ]
                      raise ValueError("I want to be raised!")
              except ValueError:
                  pass
              # This should not be captured:
              tf.summary.FileWriter("/tmp/whatever", s.graph)
              assert _run.info["tensorflow"]["logdirs"] == [
                  TEST_LOG_DIR
              ]
  
      ex.run()
  
file_path: sacred/tests/test_stflow/test_method_interception.py
imports: import pytest
  from sacred import Experiment
  from sacred.stflow import LogFileWriter
  import sacred.optional
label_desc: Use image node_id 5 for calling a global function with example usage: test_log_file_writer_as_context_manager_with_exception(ex, tf) without return types