<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def open_output_file(self, test_record):
 """Open file based on pattern."""

    # 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')