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

avocado.core.test: Refactor *SkipTests and support extra params

All *SkipTests are now inherited from "SkipTest" baseclass. This
baseclass contains improved __init__ which removes any unsupported
parameters from the Test.__init__ super call.

This is because those classes are used to substitute other avocado test
classes, for example "avocado-vt" tests which contain "vt_params"
argument unsupported by Test.__init__.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 74950101
......@@ -706,25 +706,51 @@ class NotATest(Test):
raise exceptions.NotATestError(e_msg)
class TimeOutSkipTest(Test):
class SkipTest(Test):
"""
Skip test due job timeout.
This test is skipped due a job timeout.
It will never have a chance to execute.
Class intended as generic substitute for avocado tests which fails during
setUp phase using "self._skip_reason" message.
"""
_skip_reason = "Test skipped due a job timeout!"
_skip_reason = "Generic skip test reason"
def __init__(self, *args, **kwargs):
"""
This class substitutes other classes. Let's just ignore the remaining
arguments and only set the ones supported by avocado.Test
"""
super_kwargs = dict()
args = list(reversed(args))
for arg in ["methodName", "name", "params", "base_logdir", "tag",
"job", "runner_queue"]:
if arg in kwargs:
super_kwargs[arg] = kwargs[arg]
elif args:
super_kwargs[arg] = args.pop()
super(SkipTest, self).__init__(**super_kwargs)
def setUp(self):
raise exceptions.TestSkipError(self._skip_reason)
def test(self):
raise NotImplementedError("This should never be executed!")
""" Should not be executed """
raise RuntimeError("This should never be executed!")
class TimeOutSkipTest(SkipTest):
"""
Skip test due job timeout.
This test is skipped due a job timeout.
It will never have a chance to execute.
"""
_skip_reason = "Test skipped due a job timeout!"
class DryRunTest(TimeOutSkipTest):
class DryRunTest(SkipTest):
"""
Fake test which logs itself and reports as SKIP
......@@ -739,7 +765,7 @@ class DryRunTest(TimeOutSkipTest):
super(DryRunTest, self).setUp()
class ReplaySkipTest(TimeOutSkipTest):
class ReplaySkipTest(SkipTest):
"""
Skip test due to job replay filter.
......
......@@ -8,7 +8,7 @@ if sys.version_info[:2] == (2, 6):
else:
import unittest
from avocado.core import test
from avocado.core import test, exceptions
from avocado.utils import script
PASS_SCRIPT_CONTENTS = """#!/bin/sh
......@@ -108,5 +108,66 @@ class SimpleTestClassTest(unittest.TestCase):
self.fail_script.remove()
shutil.rmtree(self.tmpdir)
class SkipTest(unittest.TestCase):
def setUp(self):
self.tests = []
def test_init(self):
# No params
self.tests.append(test.SkipTest())
self.assertRaises(exceptions.TestSkipError, self.tests[-1].setUp)
self.assertRaises(RuntimeError, self.tests[-1].test)
# Positional
self.tests.append(test.SkipTest("test", "my_name", {}, None, "1",
None, None, "extra_param1",
"extra_param2"))
self.assertEqual(self.tests[-1].name, "my_name")
self.assertEqual(self.tests[-1].tagged_name, "my_name.1")
# Kwargs
self.tests.append(test.SkipTest(methodName="test", name="my_name2",
params={}, base_logdir=None,
tag="a", job=None, runner_queue=None,
extra1="extra_param1",
extra2="extra_param2"))
self.assertEqual(self.tests[-1].name, "my_name2")
self.assertEqual(self.tests[-1].tagged_name, "my_name2.a")
# both (theoretically impossible in python, but valid for nasty tests)
# keyword args are used as they explicitly represent what they mean
self.tests.append(test.SkipTest("not used", "who cares", {}, None, "0",
None, None, "extra_param1",
"extra_param2",
methodName="test", name="my_name3",
params={}, base_logdir=None,
tag="3", job=None, runner_queue=None,
extra1="extra_param3",
extra2="extra_param4"))
self.assertEqual(self.tests[-1].name, "my_name3")
self.assertEqual(self.tests[-1].tagged_name, "my_name3.3")
# combination
self.tests.append(test.SkipTest("test", "my_name4", tag="321",
other_param="Whatever"))
self.assertEqual(self.tests[-1].name, "my_name4")
self.assertEqual(self.tests[-1].tagged_name, "my_name4.321")
# ugly combination (positional argument overrides kwargs, this only
# happens when the substituted class reorders the positional arguments.
# We try to first match keyword args and then fall-back to positional
# ones.
name = "positional_method_name_becomes_test_name"
tag = "positional_base_logdir_becomes_tag"
self.tests.append(test.SkipTest(name, None, None, tag,
methodName="test",
other_param="Whatever"))
self.assertEqual(self.tests[-1].name, name)
self.assertEqual(self.tests[-1].tagged_name, "%s.%s" % (name, tag))
def tearDown(self):
for tst in self.tests:
try:
shutil.rmtree(os.path.dirname(tst.logdir))
except Exception:
pass
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册