5 6 8 10 11 13 14 15 17 19 21 22 23 25 26 27 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 50 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 73 74 76 77 78 79 80 81 82 83 87 88 89 90 91 92 93 94 95 97 98 99 100 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 140 141 142 143 144 145 146 147 |
self.stream = unittest._WritelnDecorator(stream)
return TextTestResult(stream=self.stream)
unittest.TestResult.__init__(self) self.stream = stream
self.printErrorList(self.errors) self.printErrorList(self.failures)
for test, error in errors: self.stream.writeln(error)
"""Converts a sys.exc_info()-style tuple of values into a string.""" exctype, value, tb = err # Skip test runner traceback levels while tb and self._is_relevant_tb_level(tb): tb = tb.tb_next
f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename return '%s:%s:%s' % (filename, lineno, format_exception_only(exctype, value))
# from unittest.py
Usage: %(progName)s [options] [test] [...]
Options: -h, --help Show this message -v, --verbose Verbose output -q, --quiet Minimal output -g, --gnu-format-error Format error as described in GNU Coding Standards
Examples: %(progName)s - run default set of tests %(progName)s MyTestSuite - run suite 'MyTestSuite' %(progName)s MyTestCase.testSomething - run MyTestCase.testSomething %(progName)s MyTestCase - run all 'test*' test methods in MyTestCase """
['help', 'verbose', 'quiet', 'gnu-format-error']) if opt in ('-h', '-H', '--help'): self.usageExit() if opt in ('-q', '--quiet'): self.verbosity = 0 if opt in ('-v', '--verbose'): self.verbosity = 2 if opt in ('-g', '--gnu-format-error'): self.testRunner = TestRunner() if len(args) > 0: self.testNames = args else: self.testNames = (self.defaultTest,) self.createTests() except getopt.error, msg: self.usageExit(msg)
# taken from traceback module
"""Format the exception part of a traceback.
The arguments are the exception type and value such as given by sys.last_type and sys.last_value. """
# An instance should not have a meaningful value parameter, but # sometimes does, particularly for string exceptions, such as # >>> raise string1, string2 # deprecated # # Clear these out first because issubtype(string1, SyntaxError) # would throw another exception and mask the original problem. if (isinstance(etype, BaseException) or isinstance(etype, types.InstanceType) or etype is None or type(etype) is str): return _format_final_exc_line(etype, value)
stype = etype.__name__
if not issubclass(etype, SyntaxError): return _format_final_exc_line(stype, value)
# It was a syntax error; show exactly where the problem was found. try: msg, (filename, lineno, offset, badline) = value except Exception: pass else: lines = [] if offset is not None: lines.append('%s:' % offset) value = msg
lines.append(_format_final_exc_line(stype, value)) return ''.join(lines)
"""Return a list of a single line -- normal case for format_exception_only""" valuestr = traceback._some_str(value) if value is None or not valuestr: line = ' %s' % etype else: line = " %s: %s" % (etype, valuestr) return line |