[PATCH V6] run-tests: added '--json' functionality to store test result in json file
Anurag Goel
anurag.dsps at gmail.com
Fri Aug 22 20:44:39 UTC 2014
# HG changeset patch
# User anuraggoel <anurag.dsps at gmail.com>
# Date 1408740221 -19800
# Sat Aug 23 02:13:41 2014 +0530
# Node ID 48884fcbedc1e04e8f34e39bdc1cf7a7fd352408
# Parent 91464337202e467eb2a6d4a334b9941abf42ef16
run-tests: added '--json' functionality to store test result in json file
This patch added a new functionality '--json'. While testing, if '--json'
is enabled then test result data gets stored in newly created "report.json"
file in the following format.
testreport ={
"test-success.t": {
"result": "success",
"time": "2.041"
}
"test-failure.t": {
"result": "failure",
"time": "4.430"
}
"test-skip.t": {
"result": "skip"
"time": "3.754"
}
}
This "report.json" file will further accessed by html/javascript file for
graph usage.
diff -r 91464337202e -r 48884fcbedc1 tests/run-tests.py
--- a/tests/run-tests.py Thu Aug 21 16:23:24 2014 +0530
+++ b/tests/run-tests.py Sat Aug 23 02:13:41 2014 +0530
@@ -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.'
More information about the Mercurial-devel
mailing list