diff tests/run-tests.py @ 38616:c44ae5997869

run-tests: add support for external test result The goal is to begin experiment with custom test result. I'm not sure we should offers any backward-compatibility guarantee on that plugin API as it doesn't change often and shouldn't have too much clients. Differential Revision: https://phab.mercurial-scm.org/D3700
author Boris Feld <boris.feld@octobus.net>
date Sat, 28 Apr 2018 12:51:44 +0200
parents f83600efa1ca
children 948691ea92a9
line wrap: on
line diff
--- a/tests/run-tests.py	Thu Mar 15 17:37:03 2018 +0530
+++ b/tests/run-tests.py	Sat Apr 28 12:51:44 2018 +0200
@@ -1851,6 +1851,16 @@
                 self.stream.writeln('INTERRUPTED: %s (after %d seconds)' % (
                     test.name, self.times[-1][3]))
 
+def getTestResult():
+    """
+    Returns the relevant test result
+    """
+    if "CUSTOM_TEST_RESULT" in os.environ:
+        testresultmodule = __import__(os.environ["CUSTOM_TEST_RESULT"])
+        return testresultmodule.TestResult
+    else:
+        return TestResult
+
 class TestSuite(unittest.TestSuite):
     """Custom unittest TestSuite that knows how to execute Mercurial tests."""
 
@@ -2090,8 +2100,8 @@
         self._runner = runner
 
     def listtests(self, test):
-        result = TestResult(self._runner.options, self.stream,
-                            self.descriptions, 0)
+        result = getTestResult()(self._runner.options, self.stream,
+                                 self.descriptions, 0)
         test = sorted(test, key=lambda t: t.name)
         for t in test:
             print(t.name)
@@ -2109,9 +2119,8 @@
         return result
 
     def run(self, test):
-        result = TestResult(self._runner.options, self.stream,
-                            self.descriptions, self.verbosity)
-
+        result = getTestResult()(self._runner.options, self.stream,
+                                 self.descriptions, self.verbosity)
         test(result)
 
         failed = len(result.failures)