From c746ee11eca0f09d71e23986fb77392777e255cd Mon Sep 17 00:00:00 2001 From: Aníbal Limón Date: Fri, 26 May 2017 15:37:45 -0500 Subject: oeqa/core: Add support for run tests by module, class and name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will enable only run certain module tests and filter by class and test name. (From OE-Core rev: 0f7531803aa6ffef2b7c5be9acee3efe7d2974ef) Signed-off-by: Aníbal Limón Signed-off-by: Richard Purdie --- meta/lib/oeqa/core/context.py | 6 ++-- meta/lib/oeqa/core/loader.py | 66 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 4 deletions(-) (limited to 'meta') diff --git a/meta/lib/oeqa/core/context.py b/meta/lib/oeqa/core/context.py index bc958d0dfe..28ae017090 100644 --- a/meta/lib/oeqa/core/context.py +++ b/meta/lib/oeqa/core/context.py @@ -85,9 +85,9 @@ class OETestContextExecutor(object): help="results output log, default: %s" % self.default_output_log) group = self.parser.add_mutually_exclusive_group() - group.add_argument('--run-tests', action='store', + group.add_argument('--run-tests', action='store', nargs='+', default=self.default_tests, - help="tests to run in [.[.]] format. Just works for modules now") + help="tests to run in [.[.]]") group.add_argument('--list-tests', action='store', choices=('module', 'class', 'name'), help="lists available tests") @@ -136,7 +136,7 @@ class OETestContextExecutor(object): self.tc_kwargs['init']['td'] = {} if args.run_tests: - self.tc_kwargs['load']['modules'] = args.run_tests.split() + self.tc_kwargs['load']['modules'] = args.run_tests else: self.tc_kwargs['load']['modules'] = None diff --git a/meta/lib/oeqa/core/loader.py b/meta/lib/oeqa/core/loader.py index 63a1703536..bffb2dac8d 100644 --- a/meta/lib/oeqa/core/loader.py +++ b/meta/lib/oeqa/core/loader.py @@ -29,6 +29,51 @@ def _find_duplicated_modules(suite, directory): if path: raise ImportError("Duplicated %s module found in %s" % (module, path)) +def _built_modules_dict(modules): + modules_dict = {} + + if modules == None: + return modules_dict + + for m in modules: + ms = m.split('.') + + if len(ms) == 1: + module_name = ms[0] + if not module_name in modules_dict: + modules_dict[module_name] = {} + elif len(ms) == 2: + module_name = ms[0] + class_name = ms[1] + if not module_name in modules_dict: + modules_dict[module_name] = {} + if not class_name in modules_dict[module_name]: + modules_dict[module_name][class_name] = [] + elif len(ms) == 3: + module_name = ms[0] + class_name = ms[1] + test_name = ms[2] + + if not module_name in modules_dict: + modules_dict[module_name] = {} + if not class_name in modules_dict[module_name]: + modules_dict[module_name][class_name] = [] + if not test_name in modules_dict[module_name][class_name]: + modules_dict[module_name][class_name].append(test_name) + elif len(ms) >= 4: + module_name = '.'.join(ms[0:-2]) + class_name = ms[-2] + test_name = ms[-1] + + if not module_name in modules_dict: + modules_dict[module_name] = {} + if not class_name in modules_dict[module_name]: + modules_dict[module_name][class_name] = [] + if not test_name in modules_dict[module_name][class_name]: + modules_dict[module_name][class_name].append(test_name) + + return modules_dict + class OETestLoader(unittest.TestLoader): caseClass = OETestCase @@ -39,7 +84,8 @@ class OETestLoader(unittest.TestLoader): filters, *args, **kwargs): self.tc = tc - self.modules = modules + self.modules = _built_modules_dict(modules) + self.tests = tests self.modules_required = modules_required @@ -116,6 +162,24 @@ class OETestLoader(unittest.TestLoader): """ Returns True if test case must be filtered, False otherwise. """ + # Filters by module.class.name + module_name = case.__module__ + class_name = case.__class__.__name__ + test_name = case._testMethodName + + if self.modules: + if not module_name in self.modules: + return True + + if self.modules[module_name]: + if not class_name in self.modules[module_name]: + return True + + if self.modules[module_name][class_name]: + if test_name not in self.modules[module_name][class_name]: + return True + + # Decorator filters if self.filters: filters = self.filters.copy() case_decorators = [cd for cd in case.decorators -- cgit v1.2.3-54-g00ecf