# HG changeset patch # User Laurent Charignon # Date 2016-01-19 16:22:27 # Node ID 0de4dfc9af0c36f9ebbf06cab74d70d7bfe2ca44 # Parent 4c6053a6b17d682b34fb88bbeb5e94ed9085d900 run-tests: fix crash when --json and --blacklist are both used (issue5050) This patch fixes a crash when both --json and --blacklist were given as arguments of run-tests.py. Now, instead of crashing, we add an entry for blacklisted tests in the json output to show that the tests were skipped. diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1727,14 +1727,20 @@ class TextTestRunner(unittest.TextTestRu ('skip', result.skipped)] for res, testcases in groups: for tc, __ in testcases: - tres = {'result': res, - 'time': ('%0.3f' % timesd[tc.name][2]), - 'cuser': ('%0.3f' % timesd[tc.name][0]), - 'csys': ('%0.3f' % timesd[tc.name][1]), - 'start': ('%0.3f' % timesd[tc.name][3]), - 'end': ('%0.3f' % timesd[tc.name][4]), - 'diff': result.faildata.get(tc.name, ''), - } + if tc.name in timesd: + tres = {'result': res, + 'time': ('%0.3f' % timesd[tc.name][2]), + 'cuser': ('%0.3f' % timesd[tc.name][0]), + 'csys': ('%0.3f' % timesd[tc.name][1]), + 'start': ('%0.3f' % timesd[tc.name][3]), + 'end': ('%0.3f' % timesd[tc.name][4]), + 'diff': result.faildata.get(tc.name, + ''), + } + else: + # blacklisted test + tres = {'result': res} + outcome[tc.name] = tres jsonout = json.dumps(outcome, sort_keys=True, indent=4) fp.writelines(("testreport =", jsonout)) diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t --- a/tests/test-run-tests.t +++ b/tests/test-run-tests.t @@ -494,13 +494,21 @@ Skips with xml Missing skips or blacklisted skips don't count as executed: $ echo test-failure.t > blacklist - $ rt --blacklist=blacklist \ + $ rt --blacklist=blacklist --json\ > test-failure.t test-bogus.t ss Skipped test-bogus.t: Doesn't exist Skipped test-failure.t: blacklisted # Ran 0 tests, 2 skipped, 0 warned, 0 failed. - + $ cat report.json + testreport ={ + "test-bogus.t": { + "result": "skip" + }, + "test-failure.t": { + "result": "skip" + } + } (no-eol) #if json test for --json