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

Merge remote branch 'clebergnu/runner_and_test_misc'

Signed-off-by: NJan Richter <jarichte@redhat.com>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
Test runner module. Test runner module.
""" """
import multiprocessing.queues import multiprocessing
import os import os
import signal import signal
import sys import sys
...@@ -582,14 +582,7 @@ class TestRunner: ...@@ -582,14 +582,7 @@ class TestRunner:
summary = set() summary = set()
if self.job.sysinfo is not None: if self.job.sysinfo is not None:
self.job.sysinfo.start_job_hook() 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() queue = multiprocessing.SimpleQueue()
else:
queue = multiprocessing.queues.SimpleQueue() # pylint: disable=E1125
if timeout > 0: if timeout > 0:
deadline = time.time() + timeout deadline = time.time() + timeout
else: else:
...@@ -600,9 +593,9 @@ class TestRunner: ...@@ -600,9 +593,9 @@ class TestRunner:
self.result.tests_total = test_result_total self.result.tests_total = test_result_total
index = -1 index = -1
try: try:
for test_template in test_suite: for test_factory in test_suite:
test_template[1]["base_logdir"] = self.job.logdir test_factory[1]["base_logdir"] = self.job.logdir
test_template[1]["job"] = self.job test_factory[1]["job"] = self.job
if execution_order is None: if execution_order is None:
execution_order = self.DEFAULT_EXECUTION_ORDER execution_order = self.DEFAULT_EXECUTION_ORDER
for test_factory, variant in self._iter_suite(test_suite, variants, for test_factory, variant in self._iter_suite(test_suite, variants,
......
...@@ -34,10 +34,7 @@ class TestRunnerQueue(unittest.TestCase): ...@@ -34,10 +34,7 @@ class TestRunnerQueue(unittest.TestCase):
:param factory: the Avocado Test factory :param factory: the Avocado Test factory
:return: the last queue message from the test :return: the last queue message from the test
""" """
if hasattr(multiprocessing, 'SimpleQueue'):
queue = multiprocessing.SimpleQueue() queue = multiprocessing.SimpleQueue()
else:
queue = multiprocessing.queues.SimpleQueue() # pylint: disable=E1125
runner = TestRunner(job=self.job, result=self.result) runner = TestRunner(job=self.job, result=self.result)
runner._run_test(factory, queue) runner._run_test(factory, queue)
while not queue.empty(): while not queue.empty():
......
...@@ -248,59 +248,69 @@ class SimpleTestClassTest(unittest.TestCase): ...@@ -248,59 +248,69 @@ class SimpleTestClassTest(unittest.TestCase):
class MockingTest(unittest.TestCase): class MockingTest(unittest.TestCase):
def setUp(self): 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): def test_init_positional(self):
# No params tst = test.MockingTest("test", test.TestID(1, "my_name"),
self.tests.append(test.MockingTest())
# Positional
self.tests.append(test.MockingTest("test", test.TestID(1, "my_name"),
{}, None, "1", {}, None, "1",
None, None, "extra_param1", None, None, "extra_param1",
"extra_param2")) "extra_param2", base_logdir=self.tmpdir)
self.assertEqual(self.tests[-1].name, "1-my_name") self.assertEqual(tst.name, "1-my_name")
# Kwargs
self.tests.append(test.MockingTest(methodName="test", def test_init_kwargs(self):
tst = test.MockingTest(methodName="test",
name=test.TestID(1, "my_name2"), name=test.TestID(1, "my_name2"),
params={}, base_logdir=None, params={}, base_logdir=self.tmpdir,
tag="a", job=None, runner_queue=None, tag="a", job=None, runner_queue=None,
extra1="extra_param1", extra1="extra_param1",
extra2="extra_param2")) extra2="extra_param2")
self.assertEqual(self.tests[-1].name, "1-my_name2") self.assertEqual(tst.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 def test_positional_kwargs(self):
self.tests.append(test.MockingTest("not used", "who cares", {}, None, "0", """
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", None, None, "extra_param1",
"extra_param2", "extra_param2",
methodName="test", methodName="test",
name=test.TestID(1, "my_name3"), name=test.TestID(1, "my_name3"),
params={}, base_logdir=None, params={}, base_logdir=self.tmpdir,
tag="3", job=None, runner_queue=None, tag="3", job=None, runner_queue=None,
extra1="extra_param3", extra1="extra_param3",
extra2="extra_param4")) extra2="extra_param4")
self.assertEqual(self.tests[-1].name, "1-my_name3") self.assertEqual(tst.name, "1-my_name3")
# combination
self.tests.append(test.MockingTest("test", test.TestID(1, "my_name4"), def test_combination(self):
tst = test.MockingTest("test", test.TestID(1, "my_name4"),
tag="321", tag="321",
other_param="Whatever")) other_param="Whatever",
self.assertEqual(self.tests[-1].name, "1-my_name4") base_logdir=self.tmpdir)
# ugly combination (positional argument overrides kwargs, this only self.assertEqual(tst.name, "1-my_name4")
# happens when the substituted class reorders the positional arguments.
# We try to first match keyword args and then fall-back to positional def test_combination_2(self):
# ones. """
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" name = "positional_method_name_becomes_test_name"
tag = "positional_base_logdir_becomes_tag" 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", methodName="test",
other_param="Whatever")) other_param="Whatever",
self.assertEqual(self.tests[-1].name, "1-" + name) base_logdir=self.tmpdir)
self.assertEqual(tst.name, "1-" + name)
def tearDown(self): def tearDown(self):
for tst in self.tests: shutil.rmtree(self.tmpdir)
try:
shutil.rmtree(os.path.dirname(os.path.dirname(tst.logdir)))
except Exception:
pass
class TestID(unittest.TestCase): class TestID(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册