code: def _format_exception(err, is_failure, stdout=None, stderr=None):
      
      exctype, value, tb = err
      # Skip test runner traceback levels
      while tb and _is_relevant_tb_level(tb):
          tb = tb.tb_next
  
      if is_failure:
          # Skip assert*() traceback levels
          length = _count_relevant_tb_levels(tb)
          msgLines = traceback.format_exception(exctype, value, tb, length)
      else:
          msgLines = traceback.format_exception(exctype, value, tb)
  
      encoding = locale.getpreferredencoding()
      msgLines = [_decode(line, encoding) for line in msgLines]
  
      if stdout:
          if not stdout.endswith('\n'):
              stdout += '\n'
          msgLines.append(STDOUT_LINE % stdout)
      if stderr:
          if not stderr.endswith('\n'):
              stderr += '\n'
          msgLines.append(STDERR_LINE % stderr)
      return ''.join(msgLines)
docs: Converts a sys.exc_info()-style tuple of values into a string.