Commit 8da76aeb authored by Denis Bilenko's avatar Denis Bilenko

testrunner.py: store test's exception in the database and print it when printing stats

parent ebed9269
...@@ -114,15 +114,22 @@ class DatabaseTestResult(_TextTestResult): ...@@ -114,15 +114,22 @@ class DatabaseTestResult(_TextTestResult):
def addSuccess(self, test): def addSuccess(self, test):
_TextTestResult.addSuccess(self, test) _TextTestResult.addSuccess(self, test)
self._store_result(test, 'PASS') self._store_result(test, 'PASSED')
def addError(self, test, err): def addError(self, test, err):
_TextTestResult.addError(self, test, err) _TextTestResult.addError(self, test, err)
self._store_result(test, 'FAIL') self._store_result(test, format_exc_info(err))
def addFailure(self, test, err): def addFailure(self, test, err):
_TextTestResult.addFailure(self, test, err) _TextTestResult.addFailure(self, test, err)
self._store_result(test, 'FAIL') self._store_result(test, format_exc_info(err))
def format_exc_info(exc_info):
try:
return '%s: %s' % (exc_info[0].__name__, exc_info[1])
except:
return str(exc_info[1]) or str(exc_info[0]) or 'FAILED'
class DatabaseTestRunner(TextTestRunner): class DatabaseTestRunner(TextTestRunner):
...@@ -323,6 +330,19 @@ def get_testcases(cursor, runid, result=None): ...@@ -323,6 +330,19 @@ def get_testcases(cursor, runid, result=None):
return ['.'.join(x) for x in cursor.execute(sql, args).fetchall()] return ['.'.join(x) for x in cursor.execute(sql, args).fetchall()]
def get_failed_testcases(cursor, runid):
sql = 'select test, testcase, result from testcase where runid=?'
args = (runid, )
sql += ' and result!="PASSED" and result!="TIMEOUT"'
names = []
errors = {}
for test, testcase, result in cursor.execute(sql, args).fetchall():
name = '%s.%s' % (test, testcase)
names.append(name)
errors[name] = result
return names, errors
_warning_re = re.compile('\w*warning', re.I) _warning_re = re.compile('\w*warning', re.I)
_error_re = re.compile(r'(?P<prefix>\s*)Traceback \(most recent call last\):' + _error_re = re.compile(r'(?P<prefix>\s*)Traceback \(most recent call last\):' +
r'(\n(?P=prefix)\s+.*)+\n(?P=prefix)(?P<error>[\w\.]+)') r'(\n(?P=prefix)\s+.*)+\n(?P=prefix)(?P<error>[\w\.]+)')
...@@ -395,7 +415,7 @@ def print_stats(options): ...@@ -395,7 +415,7 @@ def print_stats(options):
options.runid = cursor.execute('select runid from test order by started_at desc limit 1').fetchall()[0][0] options.runid = cursor.execute('select runid from test order by started_at desc limit 1').fetchall()[0][0]
print 'Using the latest runid: %s' % options.runid print 'Using the latest runid: %s' % options.runid
total = len(get_testcases(cursor, options.runid)) total = len(get_testcases(cursor, options.runid))
failed = get_testcases(cursor, options.runid, 'FAIL') failed, errors = get_failed_testcases(cursor, options.runid)
timedout = get_testcases(cursor, options.runid, 'TIMEOUT') timedout = get_testcases(cursor, options.runid, 'TIMEOUT')
for test, output, retcode in cursor.execute('select test, output, retcode from test where runid=?', (options.runid, )): for test, output, retcode in cursor.execute('select test, output, retcode from test where runid=?', (options.runid, )):
info = get_info(output or '') info = get_info(output or '')
...@@ -416,8 +436,15 @@ def print_stats(options): ...@@ -416,8 +436,15 @@ def print_stats(options):
failed.append(test) failed.append(test)
total += 1 total += 1
if failed: if failed:
failed.sort()
print 'FAILURES: ' print 'FAILURES: '
print ' - ' + '\n - '.join(failed) for testcase in failed:
error = errors.get(testcase)
if error:
error = repr(error)[1:-1][:100]
print ' - %s: %s' % (testcase, error)
else:
print ' - %s' % (testcase, )
if timedout: if timedout:
print 'TIMEOUTS: ' print 'TIMEOUTS: '
print ' - ' + '\n - '.join(timedout) print ' - ' + '\n - '.join(timedout)
......
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