Comments
Patch
@@ -184,6 +184,8 @@
parser.add_option("-t", "--timeout", type="int",
help="kill errant tests after TIMEOUT seconds"
" (default: $%s or %d)" % defaults['timeout'])
+ parser.add_option("--json", action="store_true",
+ help="store test result data in 'report.json' file")
parser.add_option("--time", action="store_true",
help="time how long each test takes")
parser.add_option("--tmpdir", type="string",
@@ -1419,6 +1421,40 @@
finally:
xuf.close()
+ if self._runner.options.json:
+ try:
+ import simplejson as json
+
+ fp = open(os.path.join(self._runner._testdir,
+ 'report.json'), 'w')
+ try:
+ timest = []
+ for test, cuser, csys, real in result.times:
+ timest.append((test, real))
+
+ timesd = dict(timest)
+
+ outcome = []
+ for tc in result.successes:
+ testresult = {'result': 'success',
+ 'time': ('%0.3f' % timesd[tc.name])}
+ outcome.append((tc.name, testresult))
+ for tc, err in sorted(result.faildata.iteritems()):
+ testresult = {'result': 'failure',
+ 'time': ('%0.3f' % timesd[tc])}
+ outcome.append((tc, testresult))
+ for tc, reason in result.skipped:
+ testresult = {'result': 'skip',
+ 'time': ('%0.3f' % timesd[tc.name])}
+ outcome.append((tc.name, testresult))
+ testdata = dict(outcome)
+ fp.writelines(("testreport =", (json.dumps(testdata,
+ sort_keys=True, indent=4))))
+ finally:
+ fp.close()
+ except ImportError:
+ pass
+
self._runner._checkhglib('Tested')
self.stream.writeln('# Ran %d tests, %d skipped, %d warned, %d failed.'