python3 syntax for re-raising an error with the old traceback
This commit is contained in:
committed by
Tamara Dahlgren
parent
d2cfbf177d
commit
6574c6779b
@@ -1597,8 +1597,9 @@ def test_log_name(self):
|
||||
return 'test-%s' % self.spec.format('{name}-{hash:7}')
|
||||
|
||||
def do_test(self, dirty=False):
|
||||
test_log_file = os.path.join(os.getcwd(), self.test_log_name)
|
||||
|
||||
def test_process():
|
||||
test_log_file = os.path.join(os.getcwd(), self.test_log_name)
|
||||
with log_output(test_log_file) as logger:
|
||||
with logger.force_echo():
|
||||
tty.msg('Testing package %s' %
|
||||
@@ -1608,9 +1609,19 @@ def test_process():
|
||||
try:
|
||||
self.test()
|
||||
except Exception as e:
|
||||
type, context, traceback = sys.exc_info()
|
||||
print('Error: %s: %s' % (type, e.message))
|
||||
raise e, None, traceback
|
||||
# Catch the error and print a summary to the log file
|
||||
# so that cdash and junit reporters know about it
|
||||
exc_type, context, traceback = sys.exc_info()
|
||||
print('Error: %s: %s' % (exc_type.__name__,
|
||||
getattr(e, 'message',
|
||||
'No error message')))
|
||||
if sys.version_info[0] < 3:
|
||||
# ugly hack: exec to avoid the fact this is a syntax
|
||||
# error in python 3
|
||||
exec("raise exc_type, None, traceback",
|
||||
globals(), locals())
|
||||
else:
|
||||
raise exc_type().with_traceback(traceback)
|
||||
tty.set_debug(old_debug)
|
||||
|
||||
try:
|
||||
@@ -1618,8 +1629,7 @@ def test_process():
|
||||
self, test_process, dirty=dirty, fake=False, context='test')
|
||||
except Exception as e:
|
||||
tty.error('Tests failed. See test log for details\n'
|
||||
' %s\n' % log_file)
|
||||
|
||||
' %s\n' % test_log_file)
|
||||
|
||||
def test(self):
|
||||
pass
|
||||
|
||||
@@ -174,13 +174,15 @@ def streamify(arg, mode):
|
||||
if output in (str, str.split) or error in (str, str.split):
|
||||
result = ''
|
||||
if output in (str, str.split):
|
||||
result += text_type(out.decode('utf-8'))
|
||||
outstr = text_type(out.decode('utf-8'))
|
||||
result += outstr
|
||||
if output is str.split:
|
||||
sys.stdout.write(out)
|
||||
sys.stdout.write(outstr)
|
||||
if error in (str, str.split):
|
||||
result += text_type(err.decode('utf-8'))
|
||||
errstr = text_type(err.decode('utf-8'))
|
||||
result += errstr
|
||||
if error is str.split:
|
||||
sys.stderr.write(err)
|
||||
sys.stderr.write(errstr)
|
||||
|
||||
rc = self.returncode = proc.returncode
|
||||
if fail_on_error and rc != 0 and (rc not in ignore_errors):
|
||||
|
||||
Reference in New Issue
Block a user