提交 990a5edc 编写于 作者: L Lukáš Doktor

Test: Turn test status into a property

I'm not 100% sure, but I don't see a benefit in allowing people to
override test status from inside test. They are suppose to use
assertions, or `self.fail`-like methods. With this change it'd be harder
to manually override the test status (as can be seen on updated
unittests) but we minimize the accidental write into `self.status`
variable, which can lead to confusing results.

Note we can consider adding `set_status` method to allow setting this
property, but I'd like to avoid allowing direct `self.status = ` usage.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 403e6af2
......@@ -233,11 +233,11 @@ class Test(unittest.TestCase):
self.log.info('START %s', self.name)
self.status = None
self.fail_reason = None
self.fail_class = None
self.traceback = None
self.text_output = None
self.__status = None
self.__running = False
self.paused = False
......@@ -365,6 +365,13 @@ class Test(unittest.TestCase):
cache_dirs.append(datadir_cache)
return cache_dirs
@property
def status(self):
"""
The result status of this test
"""
return self.__status
@property
def running(self):
"""
......@@ -617,7 +624,7 @@ class Test(unittest.TestCase):
"during execution. Check the log for "
"details.")
self.status = 'PASS'
self.__status = 'PASS'
if self.__sysinfo_enabled:
self.__sysinfo_logger.end_test_hook()
......@@ -646,17 +653,17 @@ class Test(unittest.TestCase):
self._tag_start()
self._run_avocado()
except exceptions.TestBaseException as detail:
self.status = detail.status
self.__status = detail.status
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.__status = 'FAIL'
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'
self.__status = 'ERROR'
tb_info = stacktrace.tb_info(sys.exc_info())
self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
try:
......@@ -688,7 +695,7 @@ class Test(unittest.TestCase):
else:
if self.status is None:
self.status = 'INTERRUPTED'
self.__status = 'INTERRUPTED'
self.log.info("%s %s", self.status,
self.name)
......
......@@ -57,7 +57,8 @@ from avocado import Test
class FakeStatusTest(Test):
def run_avocado(self):
super(FakeStatusTest, self).run_avocado()
self.status = 'not supported'
# Please do NOT ever use this, it's for unittesting only.
self._Test__status = 'not supported'
def test(self):
pass
......
......@@ -36,7 +36,7 @@ class JSONResultTest(unittest.TestCase):
self.test_result.filename = self.tmpfile[1]
self.test_result.tests_total = 1
self.test1 = SimpleTest(job=self.job, base_logdir=self.tmpdir)
self.test1.status = 'PASS'
self.test1._Test__status = 'PASS'
self.test1.time_elapsed = 1.23
def tearDown(self):
......
......@@ -41,7 +41,7 @@ class xUnitSucceedTest(unittest.TestCase):
self.test_result = Result(FakeJob(args))
self.test_result.tests_total = 1
self.test1 = SimpleTest(job=self.job, base_logdir=self.tmpdir)
self.test1.status = 'PASS'
self.test1._Test__status = 'PASS'
self.test1.time_elapsed = 1.23
unittests_path = os.path.dirname(os.path.abspath(__file__))
self.junit_schema_path = os.path.join(unittests_path, 'junit-4.xsd')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册