提交 348d9b6d 编写于 作者: L Lukáš Doktor

Test: Turn test traceback-related variables to properties

To avoid accidental write into test-traceback-related variables, let's
turn them into properties. This makes it harder to manually fail the
test with custom exceptions, but I consider that ugly and one should
simply raise the exception and the runner should take care of setting
the class, traceback and details.

To prove the direct access is not necessary I tried this with
Avocado-vt which works without any modifications even though it uses
custom exception handling.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 990a5edc
......@@ -233,11 +233,11 @@ class Test(unittest.TestCase):
self.log.info('START %s', self.name)
self.fail_reason = None
self.fail_class = None
self.traceback = None
self.text_output = None
self.__status = None
self.__fail_reason = None
self.__fail_class = None
self.__traceback = None
self.__running = False
self.paused = False
......@@ -379,6 +379,18 @@ class Test(unittest.TestCase):
"""
return self.__running
@property
def fail_reason(self):
return self.__fail_reason
@property
def fail_class(self):
return self.__fail_class
@property
def traceback(self):
return self.__traceback
def __str__(self):
return str(self.name)
......@@ -654,25 +666,25 @@ class Test(unittest.TestCase):
self._run_avocado()
except exceptions.TestBaseException as detail:
self.__status = detail.status
self.fail_class = detail.__class__.__name__
self.fail_reason = detail
self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
self.__fail_class = detail.__class__.__name__
self.__fail_reason = detail
self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
except AssertionError as detail:
self.__status = 'FAIL'
self.fail_class = detail.__class__.__name__
self.fail_reason = detail
self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
self.__fail_class = detail.__class__.__name__
self.__fail_reason = detail
self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
except Exception as detail:
self.__status = 'ERROR'
tb_info = stacktrace.tb_info(sys.exc_info())
self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
try:
self.fail_class = str(detail.__class__.__name__)
self.fail_reason = str(detail)
self.__fail_class = str(detail.__class__.__name__)
self.__fail_reason = str(detail)
except TypeError:
self.fail_class = "Exception"
self.fail_reason = ("Unable to get exception, check the "
"traceback for details.")
self.__fail_class = "Exception"
self.__fail_reason = ("Unable to get exception, check the "
"traceback for details.")
for e_line in tb_info:
self.log.error(e_line)
finally:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册