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

avocado.core.test: Avoid None status on early exception

When avocado fails early in the process (for example in
_setup_environment_variables) it crashes, because the test status is
None. Other example could be user-defined status, which is not inside
user-facing-statuses.

This patch modifies the "status" to "ERROR" when test reports
unsupported status and sets related values to provide details regarding
this failure.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 1a2a3819
......@@ -28,6 +28,7 @@ import time
from . import test
from . import exceptions
from . import output
from . import status
from .loader import loader
from .status import mapping
from ..utils import wait
......@@ -394,6 +395,17 @@ class TestRunner(object):
if ctrl_c_count > 0:
self.job.log.debug('')
# Make sure the test status is correct
if test_state.get('status') not in status.user_facing_status:
test_state['fail_reason'] = ("Test reports unsupported test "
"status %s.\nOriginal fail_reason: %s"
"\nOriginal fail_class: %s"
% (test_state.get('status'),
test_state.get('fail_reason'),
test_state.get('fail_class')))
test_state['fail_class'] = "RUNNER"
test_state['status'] = 'ERROR'
self.result.check_test(test_state)
if test_state['status'] == "INTERRUPTED":
summary.add("INTERRUPTED")
......
......@@ -50,6 +50,18 @@ class LocalImportTest(Test):
self.log.info(hello())
'''
UNSUPPORTED_STATUS_TEST_CONTENTS = '''
from avocado import Test
class FakeStatusTest(Test):
def run_avocado(self):
super(FakeStatusTest, self).run_avocado()
self.status = 'not supported'
def test(self):
pass
'''
class RunnerOperationTest(unittest.TestCase):
......@@ -134,6 +146,22 @@ class RunnerOperationTest(unittest.TestCase):
"%s" % (self.tmpdir, mytest))
process.run(cmd_line)
def test_unsupported_status(self):
os.chdir(basedir)
with script.TemporaryScript("fake_status.py",
UNSUPPORTED_STATUS_TEST_CONTENTS,
"avocado_unsupported_status") as tst:
res = process.run("./scripts/avocado run --sysinfo=off "
"--job-results-dir %s %s --json -"
% (self.tmpdir, tst), ignore_status=True)
self.assertEqual(res.exit_status, exit_codes.AVOCADO_TESTS_FAIL)
results = json.loads(res.stdout)
self.assertEqual(results["tests"][0]["status"], "ERROR",
"%s != %s\n%s" % (results["tests"][0]["status"],
"ERROR", res))
self.assertIn("Original fail_reason: None",
results["tests"][0]["fail_reason"])
def test_runner_tests_fail(self):
os.chdir(basedir)
cmd_line = './scripts/avocado run --sysinfo=off --job-results-dir %s passtest failtest passtest' % self.tmpdir
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册