提交 12a49c59 编写于 作者: C Cleber Rosa

selftests/functional/test_standalone.py: adapt to Python 3 exceptions

Which includes the module name, and the different treatment of
exceptions that do not inherit from BaseExcpetion.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 0b1c2dd2
import os import os
import sys
import unittest import unittest
from avocado.core import exit_codes from avocado.core import exit_codes
...@@ -45,7 +46,10 @@ class StandaloneTests(unittest.TestCase): ...@@ -45,7 +46,10 @@ class StandaloneTests(unittest.TestCase):
cmd_line = './examples/tests/errortest_nasty.py -r' cmd_line = './examples/tests/errortest_nasty.py -r'
expected_rc = exit_codes.AVOCADO_TESTS_FAIL expected_rc = exit_codes.AVOCADO_TESTS_FAIL
result = self.run_and_check(cmd_line, expected_rc, 'errortest_nasty') result = self.run_and_check(cmd_line, expected_rc, 'errortest_nasty')
exc = "NastyException: Nasty-string-like-exception" if sys.version_info[0] == 3:
exc = "errortest_nasty.NastyException: Nasty-string-like-exception"
else:
exc = "NastyException: Nasty-string-like-exception"
count = result.stdout.count("\n%s" % exc) count = result.stdout.count("\n%s" % exc)
self.assertEqual(count, 2, "Exception \\n%s should be present twice in" self.assertEqual(count, 2, "Exception \\n%s should be present twice in"
"the log (once from the log, second time when parsing" "the log (once from the log, second time when parsing"
...@@ -62,8 +66,11 @@ class StandaloneTests(unittest.TestCase): ...@@ -62,8 +66,11 @@ class StandaloneTests(unittest.TestCase):
cmd_line = './examples/tests/errortest_nasty3.py -r' cmd_line = './examples/tests/errortest_nasty3.py -r'
expected_rc = exit_codes.AVOCADO_TESTS_FAIL expected_rc = exit_codes.AVOCADO_TESTS_FAIL
result = self.run_and_check(cmd_line, expected_rc, 'errortest_nasty3') result = self.run_and_check(cmd_line, expected_rc, 'errortest_nasty3')
self.assertIn("TestError: <errortest_nasty3.NastyException instance at ", if sys.version_info[0] == 3:
result.stdout) exc = "TypeError: exceptions must derive from BaseException"
else:
exc = "TestError: <errortest_nasty3.NastyException instance at "
self.assertIn(exc, result.stdout)
def test_errortest(self): def test_errortest(self):
cmd_line = './examples/tests/errortest.py -r' cmd_line = './examples/tests/errortest.py -r'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册