未验证 提交 561647d2 编写于 作者: J Jan Richter

Merge remote branch 'clebergnu/runner_and_test_misc'

Signed-off-by: NJan Richter <jarichte@redhat.com>
......@@ -17,7 +17,7 @@
Test runner module.
"""
import multiprocessing.queues
import multiprocessing
import os
import signal
import sys
......@@ -582,14 +582,7 @@ class TestRunner:
summary = set()
if self.job.sysinfo is not None:
self.job.sysinfo.start_job_hook()
# Python 3 can choose a context type for queues, but SimpleQueue
# lives directly under the module namespace
if hasattr(multiprocessing, 'SimpleQueue'):
queue = multiprocessing.SimpleQueue()
else:
queue = multiprocessing.queues.SimpleQueue() # pylint: disable=E1125
if timeout > 0:
deadline = time.time() + timeout
else:
......@@ -600,9 +593,9 @@ class TestRunner:
self.result.tests_total = test_result_total
index = -1
try:
for test_template in test_suite:
test_template[1]["base_logdir"] = self.job.logdir
test_template[1]["job"] = self.job
for test_factory in test_suite:
test_factory[1]["base_logdir"] = self.job.logdir
test_factory[1]["job"] = self.job
if execution_order is None:
execution_order = self.DEFAULT_EXECUTION_ORDER
for test_factory, variant in self._iter_suite(test_suite, variants,
......
......@@ -34,10 +34,7 @@ class TestRunnerQueue(unittest.TestCase):
:param factory: the Avocado Test factory
:return: the last queue message from the test
"""
if hasattr(multiprocessing, 'SimpleQueue'):
queue = multiprocessing.SimpleQueue()
else:
queue = multiprocessing.queues.SimpleQueue() # pylint: disable=E1125
runner = TestRunner(job=self.job, result=self.result)
runner._run_test(factory, queue)
while not queue.empty():
......
......@@ -248,59 +248,69 @@ class SimpleTestClassTest(unittest.TestCase):
class MockingTest(unittest.TestCase):
def setUp(self):
self.tests = []
self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
def test_init_minimal_params(self):
test.MockingTest(base_logdir=self.tmpdir)
def test_init(self):
# No params
self.tests.append(test.MockingTest())
# Positional
self.tests.append(test.MockingTest("test", test.TestID(1, "my_name"),
def test_init_positional(self):
tst = test.MockingTest("test", test.TestID(1, "my_name"),
{}, None, "1",
None, None, "extra_param1",
"extra_param2"))
self.assertEqual(self.tests[-1].name, "1-my_name")
# Kwargs
self.tests.append(test.MockingTest(methodName="test",
"extra_param2", base_logdir=self.tmpdir)
self.assertEqual(tst.name, "1-my_name")
def test_init_kwargs(self):
tst = test.MockingTest(methodName="test",
name=test.TestID(1, "my_name2"),
params={}, base_logdir=None,
params={}, base_logdir=self.tmpdir,
tag="a", job=None, runner_queue=None,
extra1="extra_param1",
extra2="extra_param2"))
self.assertEqual(self.tests[-1].name, "1-my_name2")
# 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.MockingTest("not used", "who cares", {}, None, "0",
extra2="extra_param2")
self.assertEqual(tst.name, "1-my_name2")
def test_positional_kwargs(self):
"""
Tests both positional and kwargs (theoretically impossible in
python, but valid for nasty tests)
keyword args are used as they explicitly represent what they mean
"""
tst = test.MockingTest("not used", "who cares", {}, None, "0",
None, None, "extra_param1",
"extra_param2",
methodName="test",
name=test.TestID(1, "my_name3"),
params={}, base_logdir=None,
params={}, base_logdir=self.tmpdir,
tag="3", job=None, runner_queue=None,
extra1="extra_param3",
extra2="extra_param4"))
self.assertEqual(self.tests[-1].name, "1-my_name3")
# combination
self.tests.append(test.MockingTest("test", test.TestID(1, "my_name4"),
extra2="extra_param4")
self.assertEqual(tst.name, "1-my_name3")
def test_combination(self):
tst = test.MockingTest("test", test.TestID(1, "my_name4"),
tag="321",
other_param="Whatever"))
self.assertEqual(self.tests[-1].name, "1-my_name4")
# 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.
other_param="Whatever",
base_logdir=self.tmpdir)
self.assertEqual(tst.name, "1-my_name4")
def test_combination_2(self):
"""
Tests an 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.MockingTest(test.TestID(1, name), None, None, tag,
tst = test.MockingTest(test.TestID(1, name), None, None, tag,
methodName="test",
other_param="Whatever"))
self.assertEqual(self.tests[-1].name, "1-" + name)
other_param="Whatever",
base_logdir=self.tmpdir)
self.assertEqual(tst.name, "1-" + name)
def tearDown(self):
for tst in self.tests:
try:
shutil.rmtree(os.path.dirname(os.path.dirname(tst.logdir)))
except Exception:
pass
shutil.rmtree(self.tmpdir)
class TestID(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册