def addFailure(self, test, err): unittest.TestResult.addFailure(self, test, err) if self.showAll: self.stream.writeln(colors.red("FAIL")) elif self.dots: self.stream.write(colors.red('F')) self.stream.flush()
def addError(self, test, err): unittest.TestResult.addError(self, test, err) if self.showAll: self.stream.writeln(colors.red("ERROR")) elif self.dots: self.stream.write(colors.red('E')) self.stream.flush()
def printErrorList(self, flavour, errors): """Print colorful test output: * Error and Failure headers are in Red. * The First/Last lines (Traceback heading and Exception) are Cyan. # Non-Django lines are Yellow. """ for test, err in errors: self.stream.writeln(colors.red(self.separator1)) out = "{0}: {1}".format(flavour, self.getDescription(test)) self.stream.writeln(colors.red(out)) self.stream.writeln(colors.red(self.separator2)) tb = "{0}".format(err) lines = tb.strip().split("\n") # Temporarily remove the first & last lines of the Traceback. if len(lines) > 2: first_line = colors.cyan(lines.pop(0)) # Traceback header last_line = colors.cyan(lines.pop(-1)) # The Exception else: first_line, last_line = ('', '') # Python 2 tracebacks are organized into pairs of lines--a path and # a line of code that looks something like this: # # >>> File "/path/to/module.py", line 123, in method_name # >>> some_line_of_code # # Python 3 tracebacks, however, may start with several lines of # output, e.g.: # # ----------------------------------------------------------------- # Traceback (most recent call last): # File "/usr/lib/python/unittest/mock.py", line 1, in _whatever # return getattr(thing, comp) # AttributeError: 'module' object has no attribute 'something' # # During handling of the above exception, another exception occurred # # ----------------------------------------------------------------- # # So, rather than trying to group every two lines (like this code # used to do), just inspect each line and if we watch a given # path, highlight it and the next line of the traceback. i = 0 while i < len(lines) - 1: if self.highlight_path in lines[i]: lines[i] = colors.yellow(lines[i]) lines[i + 1] = colors.yellow(lines[i + 1]) i += 1 lines.insert(0, first_line) lines.append(last_line) self.stream.writeln("\n".join(lines))
def printErrorList(self, flavour, errors): """Print colorful test output: * Error and Failure headers are in Red. * The First/Last lines (Traceback heading and Exception) are Cyan. # Non-Django lines are Yellow. """ # Find the path where django is installed. django_path = dirname(getfile(django)) for test, err in errors: self.stream.writeln(colors.red(self.separator1)) out = "{0}: {1}".format(flavour, self.getDescription(test)) self.stream.writeln(colors.red(out)) self.stream.writeln(colors.red(self.separator2)) tb = "{0}".format(err) lines = tb.strip().split("\n") # Temporarily remove the first & last lines of the Traceback. if len(lines) > 2: first_line = colors.cyan(lines.pop(0)) # Traceback header last_line = colors.cyan(lines.pop(-1)) # The Exception else: first_line, last_line = ('', '') # The traceback is organized into pairs; a path and a line of code, # and the pair looks something like this: # # >>> File "/path/to/module.py", line 123, in method_name # >>> some_line_of_code # # So, we'll group every two lines of the traceback, and highlight # the pertinent parts i = 0 # remember which line of the Traceback we're highlighting. groups = zip(*[lines[x::2] for x in range(2)]) for path, line_of_code in groups: if django_path not in path: lines[i] = colors.yellow(path) lines[i + 1] = colors.yellow(line_of_code) i += 2 lines.insert(0, first_line) lines.append(last_line) self.stream.writeln("\n".join(lines))
def random_sad(): return colors.red(choice(sad_messages))
def print_failure_line(self, test): line = red('failure ') + self.get_elapsed_line(test) self.stream.writeln(line)
def print_error_line(self, test): line = red('error ') + self.get_elapsed_line(test) self.stream.writeln(line)