equal
deleted
inserted
replaced
1044 |
1044 |
1045 class TestResult(unittest._TextTestResult): |
1045 class TestResult(unittest._TextTestResult): |
1046 """Holds results when executing via unittest.""" |
1046 """Holds results when executing via unittest.""" |
1047 # Don't worry too much about accessing the non-public _TextTestResult. |
1047 # Don't worry too much about accessing the non-public _TextTestResult. |
1048 # It is relatively common in Python testing tools. |
1048 # It is relatively common in Python testing tools. |
1049 def __init__(self, *args, **kwargs): |
1049 def __init__(self, options, *args, **kwargs): |
1050 super(TestResult, self).__init__(*args, **kwargs) |
1050 super(TestResult, self).__init__(*args, **kwargs) |
|
1051 |
|
1052 self._options = options |
1051 |
1053 |
1052 # unittest.TestResult didn't have skipped until 2.7. We need to |
1054 # unittest.TestResult didn't have skipped until 2.7. We need to |
1053 # polyfill it. |
1055 # polyfill it. |
1054 self.skipped = [] |
1056 self.skipped = [] |
1055 |
1057 |
1060 |
1062 |
1061 # We have a custom "warned" result that isn't present in any Python |
1063 # We have a custom "warned" result that isn't present in any Python |
1062 # unittest implementation. It is very similar to failed. It may make |
1064 # unittest implementation. It is very similar to failed. It may make |
1063 # sense to map it into fail some day. |
1065 # sense to map it into fail some day. |
1064 self.warned = [] |
1066 self.warned = [] |
|
1067 |
|
1068 def addFailure(self, *args, **kwargs): |
|
1069 super(TestResult, self).addFailure(*args, **kwargs) |
|
1070 |
|
1071 if self._options.first: |
|
1072 self.stop() |
|
1073 |
|
1074 def addError(self, *args, **kwargs): |
|
1075 super(TestResult, self).addError(*args, **kwargs) |
|
1076 |
|
1077 if self._options.first: |
|
1078 self.stop() |
1065 |
1079 |
1066 # Polyfill. |
1080 # Polyfill. |
1067 def addSkip(self, test, reason): |
1081 def addSkip(self, test, reason): |
1068 self.skipped.append((test, reason)) |
1082 self.skipped.append((test, reason)) |
1069 |
1083 |
1083 self.stream.flush() |
1097 self.stream.flush() |
1084 |
1098 |
1085 def addWarn(self, test, reason): |
1099 def addWarn(self, test, reason): |
1086 self.warned.append((test, reason)) |
1100 self.warned.append((test, reason)) |
1087 |
1101 |
|
1102 if self._options.first: |
|
1103 self.stop() |
|
1104 |
1088 if self.showAll: |
1105 if self.showAll: |
1089 self.stream.writeln('warned %s' % reason) |
1106 self.stream.writeln('warned %s' % reason) |
1090 else: |
1107 else: |
1091 self.stream.write('~') |
1108 self.stream.write('~') |
1092 self.stream.flush() |
1109 self.stream.flush() |
1111 super(TextTestRunner, self).__init__(*args, **kwargs) |
1128 super(TextTestRunner, self).__init__(*args, **kwargs) |
1112 |
1129 |
1113 self._runner = runner |
1130 self._runner = runner |
1114 |
1131 |
1115 def run(self, test): |
1132 def run(self, test): |
1116 result = TestResult(self.stream, self.descriptions, self.verbosity) |
1133 result = TestResult(self._runner.options, self.stream, |
|
1134 self.descriptions, self.verbosity) |
1117 |
1135 |
1118 test(result) |
1136 test(result) |
1119 |
1137 |
1120 failed = len(result.failures) |
1138 failed = len(result.failures) |
1121 warned = len(result.warned) |
1139 warned = len(result.warned) |
1704 try: |
1722 try: |
1705 code, test, msg = done.get(True, 1) |
1723 code, test, msg = done.get(True, 1) |
1706 self.results[code].append((test, msg)) |
1724 self.results[code].append((test, msg)) |
1707 if self.options.first and code not in '.si': |
1725 if self.options.first and code not in '.si': |
1708 break |
1726 break |
|
1727 if result and result.shouldStop: |
|
1728 break |
1709 except queue.Empty: |
1729 except queue.Empty: |
1710 continue |
1730 continue |
1711 running -= 1 |
1731 running -= 1 |
1712 if tests and not running == jobs: |
1732 if tests and not running == jobs: |
1713 test = tests.pop(0) |
1733 test = tests.pop(0) |