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

test: Store fail_reason only as string

The fail_reason is the instance of the actual exception. We do store it
only as string in case of old-type exception, but even new style
exceptions might be not available when sys.path is different causing
unpickle on runner part impossible.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 c0156e43
......@@ -707,12 +707,12 @@ class Test(unittest.TestCase):
except exceptions.TestBaseException as detail:
self.__status = detail.status
self.__fail_class = detail.__class__.__name__
self.__fail_reason = detail
self.__fail_reason = str(detail)
self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
except AssertionError as detail:
self.__status = 'FAIL'
self.__fail_class = detail.__class__.__name__
self.__fail_reason = detail
self.__fail_reason = str(detail)
self.__traceback = stacktrace.prepare_exc_info(sys.exc_info())
except Exception as detail:
self.__status = 'ERROR'
......
......@@ -114,6 +114,19 @@ class MyTest(Test):
'''
RAISE_CUSTOM_PATH_EXCEPTION_CONTENT = '''import os
import sys
from avocado import Test
class SharedLibTest(Test):
def test(self):
sys.path.append(os.path.join(os.path.dirname(__file__), "shared_lib"))
from mylib import CancelExc
raise CancelExc("This should not crash on unpickling in runner")
'''
def probe_binary(binary):
try:
return utils_path.find_command(binary)
......@@ -391,6 +404,26 @@ class RunnerOperationTest(unittest.TestCase):
result))
self.assertIn('"status": "FAIL"', result.stdout)
def test_exception_not_in_path(self):
os.chdir(basedir)
os.mkdir(os.path.join(self.tmpdir, "shared_lib"))
mylib = script.Script(os.path.join(self.tmpdir, "shared_lib",
"mylib.py"),
"from avocado import TestCancel\n\n"
"class CancelExc(TestCancel):\n"
" pass")
mylib.save()
mytest = script.Script(os.path.join(self.tmpdir, "mytest.py"),
RAISE_CUSTOM_PATH_EXCEPTION_CONTENT)
mytest.save()
result = process.run("%s --show test run --sysinfo=off "
"--job-results-dir %s %s"
% (AVOCADO, self.tmpdir, mytest))
self.assertIn("mytest.py:SharedLibTest.test -> CancelExc: This "
"should not crash on unpickling in runner",
result.stdout)
self.assertNotIn("Failed to read queue", result.stdout)
def test_runner_timeout(self):
os.chdir(basedir)
cmd_line = ('%s run --sysinfo=off --job-results-dir %s '
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册