提交 586e4f13 编写于 作者: R Rudá Moura 提交者: Rudá Moura

Merge pull request #88 from avocado-framework/fix-cleanup

avocado.test: If main test action fails, cleanup still needs to be execu...
......@@ -270,17 +270,30 @@ class Test(unittest.TestCase):
sysinfo_logger = sysinfo.SysInfo(basedir=self.sysinfodir)
self.start_logging()
sysinfo_logger.start_job_hook()
action_exception = None
cleanup_exception = None
try:
self.setup()
except Exception, details:
log_exc_info(sys.exc_info())
raise exceptions.TestSetupFail(details)
self.action()
try:
self.cleanup()
self.action()
except Exception, details:
log_exc_info(sys.exc_info())
raise exceptions.TestSetupFail(details)
action_exception = details
finally:
try:
self.cleanup()
except Exception, details:
log_exc_info(sys.exc_info())
cleanup_exception = details
# pylint: disable=E0702
if action_exception is not None:
raise action_exception
elif cleanup_exception is not None:
raise exceptions.TestSetupFail(cleanup_exception)
self.status = 'PASS'
def run_avocado(self, result=None):
......
......@@ -64,6 +64,23 @@ class RunnerOperationTest(unittest.TestCase):
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" % (expected_rc, result))
def test_runner_doublefail(self):
os.chdir(basedir)
cmd_line = './scripts/avocado --xunit run doublefail'
result = process.run(cmd_line, ignore_status=True)
output = result.stdout
expected_rc = 1
unexpected_rc = 3
self.assertNotEqual(result.exit_status, unexpected_rc,
"Avocado crashed (rc %d):\n%s" % (unexpected_rc, result))
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" % (expected_rc, result))
self.assertIn("TestError: Failing during cleanup. Yay!", output,
"Cleanup exception not printed to log output")
self.assertIn("FAIL doublefail.1 -> TestFail: This test is supposed to fail",
output,
"Test did not fail with action exception")
class RunnerDropinTest(unittest.TestCase):
......
#!/usr/bin/python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2013-2014
# Author: Lucas Meneghel Rodrigues <lmr@redhat.com>
from avocado import test
from avocado import job
from avocado.core import exceptions
class doublefail(test.Test):
"""
Functional test for avocado. Straight up fail the test.
"""
def action(self):
"""
Should fail.
"""
raise exceptions.TestFail('This test is supposed to fail')
def cleanup(self):
"""
Should also fail.
"""
raise exceptions.TestError('Failing during cleanup. Yay!')
if __name__ == "__main__":
job.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册