From 18391d8a9a266eae6bfe45edb70b1284d010705f Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 2 May 2019 09:53:46 +1000 Subject: [PATCH] Tools: autotest: produce stacktraces under Python3 --- Tools/autotest/arducopter.py | 2 +- Tools/autotest/common.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index 164cd0dab3..c1448ce5a7 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -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() diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index e8bc0d3297..9dadf17748 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -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): 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))