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

core.test: Map generic exceptions to TestError

On unhandeled unknown exceptions the test should finish with ERROR
rather than FAIL as the test developer didn't think it might happen.

This behavior is configurable in config when the user have a different
opinion.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 ca26cf25
......@@ -35,6 +35,8 @@ from . import data_dir
from . import sysinfo
from . import exceptions
from . import multiplexer
from . import status
from .settings import settings
from .version import VERSION
from ..utils import genio
from ..utils import path as utils_path
......@@ -444,7 +446,16 @@ class Test(unittest.TestCase):
self.fail_reason = detail
self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
except Exception, detail:
self.status = 'FAIL'
stat = settings.get_value("runner.behavior",
"uncaught_exception_result",
default="ERROR")
if stat not in status.mapping:
stacktrace.log_message("Incorrect runner.behavior.generic_"
"exception_result value '%s', using "
"'ERROR' instead." % stat,
"avocado.test")
stat = "ERROR"
self.status = stat
tb_info = stacktrace.tb_info(sys.exc_info())
self.traceback = stacktrace.prepare_exc_info(sys.exc_info())
try:
......
......@@ -33,6 +33,8 @@ utf8 =
[runner.behavior]
# Keep job temporary files after jobs (useful for avocado debugging)
keep_tmp_files = False
# Overrides the test result in case of uncaught exception (FAIL, ERROR, ...)
uncaught_exception_result = ERROR
[job.output]
# Base log level for --show-job-log.
......
#!/usr/bin/python
from avocado import Test
from avocado import main
class ErrorTest(Test):
"""
Example test that raises generic exception
"""
def test(self):
"""
This should end with ERROR (on default config)
"""
raise Exception("This is a generic exception")
if __name__ == "__main__":
main()
......@@ -115,6 +115,17 @@ class RunnerOperationTest(unittest.TestCase):
output,
"Test did not fail with action exception:\n%s" % output)
def test_uncaught_exception(self):
os.chdir(basedir)
cmd_line = ("./scripts/avocado run --sysinfo=off --job-results-dir %s "
"--json - uncaught_exception" % self.tmpdir)
result = process.run(cmd_line, ignore_status=True)
expected_rc = 1
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" % (expected_rc,
result))
self.assertIn('"status": "ERROR"', result.stdout)
def test_runner_timeout(self):
os.chdir(basedir)
cmd_line = './scripts/avocado run --sysinfo=off --job-results-dir %s --xunit - timeouttest' % self.tmpdir
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册