diff --git a/selftests/all/functional/avocado/basic_tests.py b/selftests/all/functional/avocado/basic_tests.py index f64ee0254f59e6f28efd6f8999138a3a50a0aa8e..b4eb4972f025b180635a02fafa23c38c8307dbb3 100644 --- a/selftests/all/functional/avocado/basic_tests.py +++ b/selftests/all/functional/avocado/basic_tests.py @@ -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): diff --git a/tests/doublefail/doublefail.py b/tests/doublefail/doublefail.py new file mode 100755 index 0000000000000000000000000000000000000000..394504ad516fa49a8ca6e62bd21c2dee206f6fa4 --- /dev/null +++ b/tests/doublefail/doublefail.py @@ -0,0 +1,43 @@ +#!/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 + + +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()