core: TestSuite config will extend from job.config if is present

If job.config is present when creating a test suite then we will extend
this configuration. This will make it possible to passa a very long job
config and only small/specific configs for each test suite with the
changes.
Signed-off-by: NBeraldo Leal <bleal@redhat.com>
上级 acee619f
......@@ -375,7 +375,8 @@ class Job:
@classmethod
def from_config(cls, job_config, suites_configs=None):
suites_configs = suites_configs or [deepcopy(job_config)]
suites = [TestSuite.from_config(config) for config in suites_configs]
suites = [TestSuite.from_config(config, job_config=job_config)
for config in suites_configs]
return cls(job_config, suites)
@property
......
......@@ -24,13 +24,15 @@ class TestSuiteStatus(Enum):
class TestSuite:
def __init__(self, name, config, tests=None):
def __init__(self, name, config, tests=None, job_config=None):
self.name = name
self.tests = tests
# Create a complete config dict with all registered options + custom
# config
self.config = settings.as_dict()
if job_config:
self.config.update(job_config)
if config:
self.config.update(config)
......@@ -142,7 +144,9 @@ class TestSuite:
return self.runner.run_suite(job, self)
@classmethod
def from_config(cls, config, name=None):
def from_config(cls, config, name=None, job_config=None):
if job_config:
config.update(job_config)
runner = config.get('run.test_runner') or 'runner'
if runner == 'nrunner':
suite = cls._from_config_with_resolver(config, name)
......
......@@ -289,6 +289,31 @@ class JobTest(unittest.TestCase):
self.assertEqual(os.path.dirname(self.job.logdir), self.tmpdir.name)
self.assertTrue(os.path.isfile(os.path.join(self.job.logdir, 'id')))
def test_job_suite_parent_config(self):
"""This will test if test suites are inheriting configs from job."""
config = {'core.show': ['none'],
'run.results_dir': self.tmpdir.name}
suite_config = {'run.references': ['/bin/true']}
# Manual/Custom method
suite = TestSuite('foo-test', config=suite_config, job_config=config)
self.job = job.Job(config, [suite])
self.assertEqual(self.job.test_suites[0].config.get('run.results_dir'),
self.tmpdir.name)
# Automatic method passing suites
self.job = job.Job.from_config(job_config=config,
suites_configs=[suite_config])
self.assertEqual(self.job.test_suites[0].config.get('run.results_dir'),
self.tmpdir.name)
# Automatic method passing only one config
config.update({'run.references': ['/bin/true']})
self.job = job.Job.from_config(job_config=config)
self.assertEqual(self.job.test_suites[0].config.get('run.results_dir'),
self.tmpdir.name)
def test_job_dryrun_no_base_logdir(self):
config = {'core.show': ['none'],
'run.store_logging_stream': [],
......
import tempfile
import unittest.mock
from avocado.core import data_dir
from avocado.core.suite import TestSuite
from avocado.utils import path as utils_path
from .. import setup_avocado_loggers, temp_dir_prefix
setup_avocado_loggers()
class TestSuiteTest(unittest.TestCase):
def setUp(self):
self.suite = None
data_dir._tmp_tracker.unittest_refresh_dir_tracker()
prefix = temp_dir_prefix(__name__, self, 'setUp')
self.tmpdir = tempfile.TemporaryDirectory(prefix=prefix)
@staticmethod
def _find_simple_test_candidates(candidates=None):
if candidates is None:
candidates = ['true']
found = []
for candidate in candidates:
try:
found.append(utils_path.find_command(candidate))
except utils_path.CmdNotFoundError:
pass
return found
def test_custom_suite(self):
"""Custom suites should assume custom tests.
When using custom suites (from constructor) we are assuming no
magic, no tests should be created from run.references.
"""
tests = self._find_simple_test_candidates()
config = {'run.results_dir': self.tmpdir.name,
'core.show': ['none'],
'run.references': tests}
self.suite = TestSuite(name='foo', config=config)
self.assertEqual(0, self.suite.size)
def test_automatic_suite(self):
"""Automatic suites should create tests.
When using automatic suites we are assuming magic,
and, tests should be created from run.references.
"""
tests = self._find_simple_test_candidates()
config = {'run.results_dir': self.tmpdir.name,
'core.show': ['none'],
'run.references': tests}
self.suite = TestSuite.from_config(config=config)
self.assertEqual(1, self.suite.size)
def test_config_extend_manual(self):
"""Test extends config from job when using manual method."""
tests = self._find_simple_test_candidates()
job_config = {'run.results_dir': self.tmpdir.name,
'core.show': ['none']}
suite_config = {'run.references': tests}
self.suite = TestSuite(name='foo',
config=suite_config,
job_config=job_config)
self.assertEqual(self.suite.config.get('core.show'), ['none'])
def test_config_extend_automatic(self):
"""Test extends config from job when using automatic method."""
tests = self._find_simple_test_candidates()
job_config = {'run.results_dir': self.tmpdir.name,
'core.show': ['none']}
suite_config = {'run.references': tests}
self.suite = TestSuite.from_config(config=suite_config,
job_config=job_config)
self.assertEqual(self.suite.config.get('core.show'), ['none'])
def tearDown(self):
data_dir._tmp_tracker.unittest_refresh_dir_tracker()
self.tmpdir.cleanup()
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册