code: def open_output_file(self, test_record):
      
      # Ignore keys for the log filename to not convert larger data structures.
      record_dict = data.convert_to_base_types(
          test_record, ignore_keys=('code_info', 'phases', 'log_records'))
      pattern = self.filename_pattern
      if isinstance(pattern, six.string_types) or callable(pattern):
        output_file = self.open_file(util.format_string(pattern, record_dict))
        try:
          yield output_file
        finally:
          output_file.close()
      elif hasattr(self.filename_pattern, 'write'):
        yield self.filename_pattern
      else:
        raise ValueError(
            'filename_pattern must be string, callable, or File-like object')
docs: Open file based on pattern.