Show More
@@ -1710,6 +1710,14 class TestResult(unittest._TextTestResul | |||||
1710 | else: # 'always', for testing purposes |
|
1710 | else: # 'always', for testing purposes | |
1711 | self.color = pygmentspresent |
|
1711 | self.color = pygmentspresent | |
1712 |
|
1712 | |||
|
1713 | def onStart(self, test): | |||
|
1714 | """ Can be overriden by custom TestResult | |||
|
1715 | """ | |||
|
1716 | ||||
|
1717 | def onEnd(self): | |||
|
1718 | """ Can be overriden by custom TestResult | |||
|
1719 | """ | |||
|
1720 | ||||
1713 | def addFailure(self, test, reason): |
|
1721 | def addFailure(self, test, reason): | |
1714 | self.failures.append((test, reason)) |
|
1722 | self.failures.append((test, reason)) | |
1715 |
|
1723 | |||
@@ -2098,71 +2106,73 class TextTestRunner(unittest.TextTestRu | |||||
2098 | super(TextTestRunner, self).__init__(*args, **kwargs) |
|
2106 | super(TextTestRunner, self).__init__(*args, **kwargs) | |
2099 |
|
2107 | |||
2100 | self._runner = runner |
|
2108 | self._runner = runner | |
|
2109 | self._result = getTestResult()(self._runner.options, self.stream, | |||
|
2110 | self.descriptions, 0) | |||
2101 |
|
2111 | |||
2102 | def listtests(self, test): |
|
2112 | def listtests(self, test): | |
2103 | result = getTestResult()(self._runner.options, self.stream, |
|
|||
2104 | self.descriptions, 0) |
|
|||
2105 | test = sorted(test, key=lambda t: t.name) |
|
2113 | test = sorted(test, key=lambda t: t.name) | |
|
2114 | ||||
|
2115 | self._result.onStart(test) | |||
|
2116 | ||||
2106 | for t in test: |
|
2117 | for t in test: | |
2107 | print(t.name) |
|
2118 | print(t.name) | |
2108 | result.addSuccess(t) |
|
2119 | self._result.addSuccess(t) | |
2109 |
|
2120 | |||
2110 | if self._runner.options.xunit: |
|
2121 | if self._runner.options.xunit: | |
2111 | with open(self._runner.options.xunit, "wb") as xuf: |
|
2122 | with open(self._runner.options.xunit, "wb") as xuf: | |
2112 | self._writexunit(result, xuf) |
|
2123 | self._writexunit(self._result, xuf) | |
2113 |
|
2124 | |||
2114 | if self._runner.options.json: |
|
2125 | if self._runner.options.json: | |
2115 | jsonpath = os.path.join(self._runner._outputdir, b'report.json') |
|
2126 | jsonpath = os.path.join(self._runner._outputdir, b'report.json') | |
2116 | with open(jsonpath, 'w') as fp: |
|
2127 | with open(jsonpath, 'w') as fp: | |
2117 | self._writejson(result, fp) |
|
2128 | self._writejson(self._result, fp) | |
2118 |
|
2129 | |||
2119 | return result |
|
2130 | return self._result | |
2120 |
|
2131 | |||
2121 | def run(self, test): |
|
2132 | def run(self, test): | |
2122 | result = getTestResult()(self._runner.options, self.stream, |
|
2133 | self._result.onStart(test) | |
2123 | self.descriptions, self.verbosity) |
|
2134 | test(self._result) | |
2124 | test(result) |
|
2135 | ||
2125 |
|
2136 | failed = len(self._result.failures) | ||
2126 |
|
|
2137 | skipped = len(self._result.skipped) | |
2127 |
|
|
2138 | ignored = len(self._result.ignored) | |
2128 | ignored = len(result.ignored) |
|
|||
2129 |
|
2139 | |||
2130 | with iolock: |
|
2140 | with iolock: | |
2131 | self.stream.writeln('') |
|
2141 | self.stream.writeln('') | |
2132 |
|
2142 | |||
2133 | if not self._runner.options.noskips: |
|
2143 | if not self._runner.options.noskips: | |
2134 | for test, msg in result.skipped: |
|
2144 | for test, msg in self._result.skipped: | |
2135 | formatted = 'Skipped %s: %s\n' % (test.name, msg) |
|
2145 | formatted = 'Skipped %s: %s\n' % (test.name, msg) | |
2136 | self.stream.write(highlightmsg(formatted, result.color)) |
|
2146 | self.stream.write(highlightmsg(formatted, self._result.color)) | |
2137 | for test, msg in result.failures: |
|
2147 | for test, msg in self._result.failures: | |
2138 | formatted = 'Failed %s: %s\n' % (test.name, msg) |
|
2148 | formatted = 'Failed %s: %s\n' % (test.name, msg) | |
2139 | self.stream.write(highlightmsg(formatted, result.color)) |
|
2149 | self.stream.write(highlightmsg(formatted, self._result.color)) | |
2140 | for test, msg in result.errors: |
|
2150 | for test, msg in self._result.errors: | |
2141 | self.stream.writeln('Errored %s: %s' % (test.name, msg)) |
|
2151 | self.stream.writeln('Errored %s: %s' % (test.name, msg)) | |
2142 |
|
2152 | |||
2143 | if self._runner.options.xunit: |
|
2153 | if self._runner.options.xunit: | |
2144 | with open(self._runner.options.xunit, "wb") as xuf: |
|
2154 | with open(self._runner.options.xunit, "wb") as xuf: | |
2145 | self._writexunit(result, xuf) |
|
2155 | self._writexunit(self._result, xuf) | |
2146 |
|
2156 | |||
2147 | if self._runner.options.json: |
|
2157 | if self._runner.options.json: | |
2148 | jsonpath = os.path.join(self._runner._outputdir, b'report.json') |
|
2158 | jsonpath = os.path.join(self._runner._outputdir, b'report.json') | |
2149 | with open(jsonpath, 'w') as fp: |
|
2159 | with open(jsonpath, 'w') as fp: | |
2150 | self._writejson(result, fp) |
|
2160 | self._writejson(self._result, fp) | |
2151 |
|
2161 | |||
2152 | self._runner._checkhglib('Tested') |
|
2162 | self._runner._checkhglib('Tested') | |
2153 |
|
2163 | |||
2154 | savetimes(self._runner._outputdir, result) |
|
2164 | savetimes(self._runner._outputdir, self._result) | |
2155 |
|
2165 | |||
2156 | if failed and self._runner.options.known_good_rev: |
|
2166 | if failed and self._runner.options.known_good_rev: | |
2157 | self._bisecttests(t for t, m in result.failures) |
|
2167 | self._bisecttests(t for t, m in self._result.failures) | |
2158 | self.stream.writeln( |
|
2168 | self.stream.writeln( | |
2159 | '# Ran %d tests, %d skipped, %d failed.' |
|
2169 | '# Ran %d tests, %d skipped, %d failed.' | |
2160 | % (result.testsRun, skipped + ignored, failed)) |
|
2170 | % (self._result.testsRun, skipped + ignored, failed)) | |
2161 | if failed: |
|
2171 | if failed: | |
2162 | self.stream.writeln('python hash seed: %s' % |
|
2172 | self.stream.writeln('python hash seed: %s' % | |
2163 | os.environ['PYTHONHASHSEED']) |
|
2173 | os.environ['PYTHONHASHSEED']) | |
2164 | if self._runner.options.time: |
|
2174 | if self._runner.options.time: | |
2165 | self.printtimes(result.times) |
|
2175 | self.printtimes(self._result.times) | |
2166 |
|
2176 | |||
2167 | if self._runner.options.exceptions: |
|
2177 | if self._runner.options.exceptions: | |
2168 | exceptions = aggregateexceptions( |
|
2178 | exceptions = aggregateexceptions( | |
@@ -2185,7 +2195,7 class TextTestRunner(unittest.TextTestRu | |||||
2185 |
|
2195 | |||
2186 | self.stream.flush() |
|
2196 | self.stream.flush() | |
2187 |
|
2197 | |||
2188 | return result |
|
2198 | return self._result | |
2189 |
|
2199 | |||
2190 | def _bisecttests(self, tests): |
|
2200 | def _bisecttests(self, tests): | |
2191 | bisectcmd = ['hg', 'bisect'] |
|
2201 | bisectcmd = ['hg', 'bisect'] | |
@@ -2751,6 +2761,8 class TestRunner(object): | |||||
2751 | if result.failures: |
|
2761 | if result.failures: | |
2752 | failed = True |
|
2762 | failed = True | |
2753 |
|
2763 | |||
|
2764 | result.onEnd() | |||
|
2765 | ||||
2754 | if self.options.anycoverage: |
|
2766 | if self.options.anycoverage: | |
2755 | self._outputcoverage() |
|
2767 | self._outputcoverage() | |
2756 | except KeyboardInterrupt: |
|
2768 | except KeyboardInterrupt: |
General Comments 0
You need to be logged in to leave comments.
Login now