Show More
@@ -0,0 +1,46 b'' | |||
|
1 | from __future__ import print_function | |
|
2 | ||
|
3 | import unittest | |
|
4 | ||
|
5 | class TestResult(unittest._TextTestResult): | |
|
6 | ||
|
7 | def __init__(self, options, *args, **kwargs): | |
|
8 | super(TestResult, self).__init__(*args, **kwargs) | |
|
9 | self._options = options | |
|
10 | ||
|
11 | # unittest.TestResult didn't have skipped until 2.7. We need to | |
|
12 | # polyfill it. | |
|
13 | self.skipped = [] | |
|
14 | ||
|
15 | # We have a custom "ignored" result that isn't present in any Python | |
|
16 | # unittest implementation. It is very similar to skipped. It may make | |
|
17 | # sense to map it into skip some day. | |
|
18 | self.ignored = [] | |
|
19 | ||
|
20 | self.times = [] | |
|
21 | self._firststarttime = None | |
|
22 | # Data stored for the benefit of generating xunit reports. | |
|
23 | self.successes = [] | |
|
24 | self.faildata = {} | |
|
25 | ||
|
26 | def addFailure(self, test, reason): | |
|
27 | print("FAILURE!", test, reason) | |
|
28 | ||
|
29 | def addSuccess(self, test): | |
|
30 | print("SUCCESS!", test) | |
|
31 | ||
|
32 | def addError(self, test, err): | |
|
33 | print("ERR!", test, err) | |
|
34 | ||
|
35 | # Polyfill. | |
|
36 | def addSkip(self, test, reason): | |
|
37 | print("SKIP!", test, reason) | |
|
38 | ||
|
39 | def addIgnore(self, test, reason): | |
|
40 | print("IGNORE!", test, reason) | |
|
41 | ||
|
42 | def addOutputMismatch(self, test, ret, got, expected): | |
|
43 | return False | |
|
44 | ||
|
45 | def stopTest(self, test, interrupted=False): | |
|
46 | super(TestResult, self).stopTest(test) |
@@ -1851,6 +1851,16 b' class TestResult(unittest._TextTestResul' | |||
|
1851 | 1851 | self.stream.writeln('INTERRUPTED: %s (after %d seconds)' % ( |
|
1852 | 1852 | test.name, self.times[-1][3])) |
|
1853 | 1853 | |
|
1854 | def getTestResult(): | |
|
1855 | """ | |
|
1856 | Returns the relevant test result | |
|
1857 | """ | |
|
1858 | if "CUSTOM_TEST_RESULT" in os.environ: | |
|
1859 | testresultmodule = __import__(os.environ["CUSTOM_TEST_RESULT"]) | |
|
1860 | return testresultmodule.TestResult | |
|
1861 | else: | |
|
1862 | return TestResult | |
|
1863 | ||
|
1854 | 1864 | class TestSuite(unittest.TestSuite): |
|
1855 | 1865 | """Custom unittest TestSuite that knows how to execute Mercurial tests.""" |
|
1856 | 1866 | |
@@ -2090,8 +2100,8 b' class TextTestRunner(unittest.TextTestRu' | |||
|
2090 | 2100 | self._runner = runner |
|
2091 | 2101 | |
|
2092 | 2102 | def listtests(self, test): |
|
2093 | result = TestResult(self._runner.options, self.stream, | |
|
2094 | self.descriptions, 0) | |
|
2103 | result = getTestResult()(self._runner.options, self.stream, | |
|
2104 | self.descriptions, 0) | |
|
2095 | 2105 | test = sorted(test, key=lambda t: t.name) |
|
2096 | 2106 | for t in test: |
|
2097 | 2107 | print(t.name) |
@@ -2109,9 +2119,8 b' class TextTestRunner(unittest.TextTestRu' | |||
|
2109 | 2119 | return result |
|
2110 | 2120 | |
|
2111 | 2121 | def run(self, test): |
|
2112 | result = TestResult(self._runner.options, self.stream, | |
|
2113 | self.descriptions, self.verbosity) | |
|
2114 | ||
|
2122 | result = getTestResult()(self._runner.options, self.stream, | |
|
2123 | self.descriptions, self.verbosity) | |
|
2115 | 2124 | test(result) |
|
2116 | 2125 | |
|
2117 | 2126 | failed = len(result.failures) |
@@ -1246,6 +1246,15 b' Test globbing of local IP addresses' | |||
|
1246 | 1246 | $ echo dead:beef::1 |
|
1247 | 1247 | $LOCALIP (glob) |
|
1248 | 1248 | |
|
1249 | Add support for external test formatter | |
|
1250 | ======================================= | |
|
1251 | ||
|
1252 | $ CUSTOM_TEST_RESULT=basic_test_result $PYTHON $TESTDIR/run-tests.py --with-hg=`which hg` "$@" test-success.t test-failure.t | |
|
1253 | ||
|
1254 | # Ran 2 tests, 0 skipped, 0 failed. | |
|
1255 | FAILURE! test-failure.t output changed | |
|
1256 | SUCCESS! test-success.t | |
|
1257 | ||
|
1249 | 1258 | Test reusability for third party tools |
|
1250 | 1259 | ====================================== |
|
1251 | 1260 |
General Comments 0
You need to be logged in to leave comments.
Login now