Commit 11b77fc7 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Group test cases by python module in test runner. Add a column with the number

of successful tests.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@879 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 9d430427
...@@ -84,13 +84,15 @@ class NeoTestRunner(unittest.TestResult): ...@@ -84,13 +84,15 @@ class NeoTestRunner(unittest.TestResult):
suite.run(self) suite.run(self)
class ModuleStats(object): class ModuleStats(object):
run = 0
errors = 0 errors = 0
success = 0 success = 0
failures = 0 failures = 0
time = 0.0 time = 0.0
def _getModuleStats(self, test): def _getModuleStats(self, test):
module = test.__class__.__name__ module = test.__class__.__module__
module = tuple(module.split('.'))
try: try:
return self.modulesStats[module] return self.modulesStats[module]
except KeyError: except KeyError:
...@@ -101,11 +103,13 @@ class NeoTestRunner(unittest.TestResult): ...@@ -101,11 +103,13 @@ class NeoTestRunner(unittest.TestResult):
stats.time += time.time() - self.lastStart stats.time += time.time() - self.lastStart
def startTest(self, test): def startTest(self, test):
print test.__class__.__module__, test._TestCase__testMethodName
unittest.TestResult.startTest(self, test) unittest.TestResult.startTest(self, test)
module = test.__class__.__name__ module = test.__class__.__name__
method = test._TestCase__testMethodName method = test._TestCase__testMethodName
print test
logging.info(" * TEST %s" % test) logging.info(" * TEST %s" % test)
stats = self._getModuleStats(test)
stats.run += 1
self.lastStart = time.time() self.lastStart = time.time()
def addSuccess(self, test): def addSuccess(self, test):
...@@ -145,22 +149,40 @@ class NeoTestRunner(unittest.TestResult): ...@@ -145,22 +149,40 @@ class NeoTestRunner(unittest.TestResult):
return s return s
def _buildSummary(self): def _buildSummary(self):
# visual
header = "%25s | run | success | errors | fails | time \n" % 'Test Module'
separator = "%25s-+---------+---------+---------+---------+----------\n" % ('-' * 25)
format = "%25s | %3s | %3s | %3s | %3s | %6.2fs \n"
group_f = "%25s | | | | | \n"
# header
s = ' ' * 30 + ' NEO TESTS REPORT' s = ' ' * 30 + ' NEO TESTS REPORT'
s += '\n' s += '\n\n'
s += self._buildSystemInfo() s += self._buildSystemInfo()
s += '\n' s += '\n' + header + separator
s += " Test Module | run | error | fail | time \n" group = None
s += "-----------------------------------+--------+--------+--------+----------\n" t_success = 0
format = "%34s | %3d | %3s | %3s | %6.2fs \n" # for each test case
for k, v in self.modulesStats.items(): for k, v in sorted(self.modulesStats.items()):
# test case stats
t_success += v.success
run, success = v.run or '.', v.success or '.'
errors, failures = v.errors or '.', v.failures or '.' errors, failures = v.errors or '.', v.failures or '.'
args = (k, v.success, errors, failures, v.time) name = k[-1].lstrip('test')
args = (name, run, success, errors, failures, v.time)
s += format % args s += format % args
s += "-----------------------------------+--------+--------+--------+----------\n" # display group below its content
_group = '.'.join(k[:-1])
if group is None:
group = _group
if _group != group:
s += separator + group_f % group + separator
group = _group
# the last group
s += separator + group_f % group + separator
# the final summary
errors, failures = len(self.errors) or '.', len(self.failures) or '.' errors, failures = len(self.errors) or '.', len(self.failures) or '.'
args = ("Summary", self.testsRun, errors, failures, self.time) args = ("Summary", self.testsRun, t_success, errors, failures, self.time)
s += format % args s += format % args + separator + '\n'
s += '\n'
return s return s
def _buildErrors(self): def _buildErrors(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment