Browse Source

Tools: autotest: produce stacktraces under Python3

master
Peter Barker 6 years ago committed by Peter Barker
parent
commit
18391d8a9a
  1. 2
      Tools/autotest/arducopter.py
  2. 16
      Tools/autotest/common.py

2
Tools/autotest/arducopter.py

@ -2992,7 +2992,7 @@ class AutoTestCopter(AutoTest): @@ -2992,7 +2992,7 @@ class AutoTestCopter(AutoTest):
self.loiter_to_ne(start.x + 5, start.y - 10, start.z + 10)
except Exception as e:
self.progress("Exception caught: %s" % traceback.format_exc(e))
self.progress("Exception caught: %s" % self.get_exception_stacktrace(e))
ex = e
self.context_pop()

16
Tools/autotest/common.py

@ -1784,6 +1784,15 @@ class AutoTest(ABC): @@ -1784,6 +1784,15 @@ class AutoTest(ABC):
def send_statustext(self, text):
self.mav.mav.statustext_send(mavutil.mavlink.MAV_SEVERITY_WARNING, bytes(text))
def get_exception_stacktrace(self, e):
if sys.version_info[0] >= 3:
ret = "%s\n" % e
ret += ''.join(traceback.format_exception(etype=type(e),
value=e,
tb=e.__traceback__))
return ret
return traceback.format_exc(e)
def run_one_test(self, name, desc, test_function, interact=False):
'''new-style run-one-test used by run_tests'''
test_output_filename = self.buildlogs_path("%s-%s.txt" %
@ -1807,12 +1816,7 @@ class AutoTest(ABC): @@ -1807,12 +1816,7 @@ class AutoTest(ABC):
test_function()
except Exception as e:
self.test_timings[desc] = time.time() - start_time
try:
stacktrace = traceback.format_exc(e)
except Exception:
# seems to be broken under Python3:
stacktrace = "stacktrace unavailable"
self.progress("Exception caught: %s" % stacktrace)
self.progress("Exception caught: %s" % self.get_exception_stacktrace(e))
self.context_pop()
self.progress('FAILED: "%s": %s (see %s)' %
(prettyname, repr(e), test_output_filename))

Loading…
Cancel
Save