Merge "Track failures during sorting of test results"

This commit is contained in:
Jenkins 2017-01-30 14:35:24 +00:00 committed by Gerrit Code Review
commit f0e3a1a014
2 changed files with 23 additions and 7 deletions

View File

@ -617,18 +617,31 @@ class HtmlOutput(testtools.TestResult):
# unittest does not seems to run in any particular order. # unittest does not seems to run in any particular order.
# Here at least we want to group them together by class. # Here at least we want to group them together by class.
rmap = {} rmap = {}
classes = []
# Differentiate between classes that have test failures so we can sort # Differentiate between classes that have test failures so we can sort
# them at the top of the html page for easier troubleshooting # them at the top of the html page for easier troubleshooting
failclasses = [] clsmap_has_failure = collections.defaultdict(bool)
passclasses = []
def track_has_failure(name, n):
if n == 1 or n == 2:
clsmap_has_failure[name] = True
for n, t, o, e in result_list: for n, t, o, e in result_list:
classes = failclasses if n == 1 or n == 2 else passclasses
if hasattr(t, '_tests'): if hasattr(t, '_tests'):
for inner_test in t._tests: for inner_test in t._tests:
self._add_cls(rmap, classes, inner_test, name = self._add_cls(rmap, classes, inner_test,
(n, inner_test, o, e)) (n, inner_test, o, e))
track_has_failure(name, n)
else: else:
self._add_cls(rmap, classes, t, (n, t, o, e)) name = self._add_cls(rmap, classes, t, (n, t, o, e))
track_has_failure(name, n)
failclasses = []
passclasses = []
for cls in classes:
append_to = (failclasses if clsmap_has_failure[str(cls)]
else passclasses)
append_to.append(cls)
classort = lambda s: str(s) classort = lambda s: str(s)
sortedfailclasses = sorted(failclasses, key=classort) sortedfailclasses = sorted(failclasses, key=classort)
sortedpassclasses = sorted(passclasses, key=classort) sortedpassclasses = sorted(passclasses, key=classort)
@ -649,6 +662,7 @@ class HtmlOutput(testtools.TestResult):
rmap[str(cls)] = [] rmap[str(cls)] = []
classes.append(cls) classes.append(cls)
rmap[str(cls)].append(data_tuple) rmap[str(cls)].append(data_tuple)
return str(cls)
def _generate_report_test(self, rows, cid, tid, n, t, o, e): def _generate_report_test(self, rows, cid, tid, n, t, o, e):
# e.g. 'pt1.1', 'ft1.1', etc # e.g. 'pt1.1', 'ft1.1', etc

View File

@ -54,8 +54,10 @@ class TestSubunit2html(base.TestCase):
# example.path.to.test4 has a failure # example.path.to.test4 has a failure
obj.addFailure(tests[4], err) obj.addFailure(tests[4], err)
obj.addSuccess(tests[7]) obj.addSuccess(tests[7])
# example.path.to.test6 has a failure # example.path.to.test6 has a success, a failure, and a success
obj.addSuccess(tests[6])
obj.addFailure(tests[6], err) obj.addFailure(tests[6], err)
obj.addSuccess(tests[6])
sorted_result = obj._sortResult(obj.result) sorted_result = obj._sortResult(obj.result)
# _sortResult returns a list of results of format: # _sortResult returns a list of results of format:
# [(class, [test_result_tuple, ...]), ...] # [(class, [test_result_tuple, ...]), ...]