selftests/functional: Verify that cleanup is called on action failure

So we don't incur in the bug we just fixed.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 82c9f6b1
......@@ -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.
先完成此消息的编辑!
想要评论请 注册