mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 13:09:50 +00:00
oeqa/core/loader: Fix filtering on test modules with submodules
Our filtering allows to specify which tests to run using, <module_name>.[test_class].[test_name] But the module name logic was restricted to only accept one level, for example: runtime_test vs oelib.types, to support multiple submodules use only the first part for filtering. This allows to run the whole tests in a module with more than tree levels. Due to the ambiguity on the test filtering options with test cases with more than tree levels the supported sytnax is, <module> or <module>.[submoduleN].[test_class].[test_name] [YOCTO #11632] (From OE-Core rev: cf2ee12b007e5570959ccfbb643159b21d90426e) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
cbe13b3b10
commit
652df69b02
@@ -164,8 +164,11 @@ class OETestLoader(unittest.TestLoader):
|
|||||||
"""
|
"""
|
||||||
Returns True if test case must be filtered, False otherwise.
|
Returns True if test case must be filtered, False otherwise.
|
||||||
"""
|
"""
|
||||||
# Filters by module.class.name
|
# XXX; If the module has more than one namespace only use
|
||||||
module_name = case.__module__
|
# the first to support run the whole module specifying the
|
||||||
|
# <module_name>.[test_class].[test_name]
|
||||||
|
module_name = case.__module__.split('.')[0]
|
||||||
|
|
||||||
class_name = case.__class__.__name__
|
class_name = case.__class__.__name__
|
||||||
test_name = case._testMethodName
|
test_name = case._testMethodName
|
||||||
|
|
||||||
@@ -278,6 +281,33 @@ class OETestLoader(unittest.TestLoader):
|
|||||||
|
|
||||||
return self.suiteClass(cases) if cases else big_suite
|
return self.suiteClass(cases) if cases else big_suite
|
||||||
|
|
||||||
|
def _filterModule(self, module):
|
||||||
|
if module.__name__ in sys.builtin_module_names:
|
||||||
|
msg = 'Tried to import %s test module but is a built-in'
|
||||||
|
raise ImportError(msg % module.__name__)
|
||||||
|
|
||||||
|
# XXX; If the module has more than one namespace only use
|
||||||
|
# the first to support run the whole module specifying the
|
||||||
|
# <module_name>.[test_class].[test_name]
|
||||||
|
module_name = module.__name__.split('.')[0]
|
||||||
|
|
||||||
|
# Normal test modules are loaded if no modules were specified,
|
||||||
|
# if module is in the specified module list or if 'all' is in
|
||||||
|
# module list.
|
||||||
|
# Underscore modules are loaded only if specified in module list.
|
||||||
|
load_module = True if not module_name.startswith('_') \
|
||||||
|
and (not self.modules \
|
||||||
|
or module_name in self.modules \
|
||||||
|
or 'all' in self.modules) \
|
||||||
|
else False
|
||||||
|
|
||||||
|
load_underscore = True if module_name.startswith('_') \
|
||||||
|
and module_name in self.modules \
|
||||||
|
else False
|
||||||
|
|
||||||
|
return (load_module, load_underscore)
|
||||||
|
|
||||||
|
|
||||||
# XXX After Python 3.5, remove backward compatibility hacks for
|
# XXX After Python 3.5, remove backward compatibility hacks for
|
||||||
# use_load_tests deprecation via *args and **kws. See issue 16662.
|
# use_load_tests deprecation via *args and **kws. See issue 16662.
|
||||||
if sys.version_info >= (3,5):
|
if sys.version_info >= (3,5):
|
||||||
@@ -285,23 +315,7 @@ class OETestLoader(unittest.TestLoader):
|
|||||||
"""
|
"""
|
||||||
Returns a suite of all tests cases contained in module.
|
Returns a suite of all tests cases contained in module.
|
||||||
"""
|
"""
|
||||||
if module.__name__ in sys.builtin_module_names:
|
load_module, load_underscore = self._filterModule(module)
|
||||||
msg = 'Tried to import %s test module but is a built-in'
|
|
||||||
raise ImportError(msg % module.__name__)
|
|
||||||
|
|
||||||
# Normal test modules are loaded if no modules were specified,
|
|
||||||
# if module is in the specified module list or if 'all' is in
|
|
||||||
# module list.
|
|
||||||
# Underscore modules are loaded only if specified in module list.
|
|
||||||
load_module = True if not module.__name__.startswith('_') \
|
|
||||||
and (not self.modules \
|
|
||||||
or module.__name__ in self.modules \
|
|
||||||
or 'all' in self.modules) \
|
|
||||||
else False
|
|
||||||
|
|
||||||
load_underscore = True if module.__name__.startswith('_') \
|
|
||||||
and module.__name__ in self.modules \
|
|
||||||
else False
|
|
||||||
|
|
||||||
if load_module or load_underscore:
|
if load_module or load_underscore:
|
||||||
return super(OETestLoader, self).loadTestsFromModule(
|
return super(OETestLoader, self).loadTestsFromModule(
|
||||||
@@ -313,23 +327,7 @@ class OETestLoader(unittest.TestLoader):
|
|||||||
"""
|
"""
|
||||||
Returns a suite of all tests cases contained in module.
|
Returns a suite of all tests cases contained in module.
|
||||||
"""
|
"""
|
||||||
if module.__name__ in sys.builtin_module_names:
|
load_module, load_underscore = self._filterModule(module)
|
||||||
msg = 'Tried to import %s test module but is a built-in'
|
|
||||||
raise ImportError(msg % module.__name__)
|
|
||||||
|
|
||||||
# Normal test modules are loaded if no modules were specified,
|
|
||||||
# if module is in the specified module list or if 'all' is in
|
|
||||||
# module list.
|
|
||||||
# Underscore modules are loaded only if specified in module list.
|
|
||||||
load_module = True if not module.__name__.startswith('_') \
|
|
||||||
and (not self.modules \
|
|
||||||
or module.__name__ in self.modules \
|
|
||||||
or 'all' in self.modules) \
|
|
||||||
else False
|
|
||||||
|
|
||||||
load_underscore = True if module.__name__.startswith('_') \
|
|
||||||
and module.__name__ in self.modules \
|
|
||||||
else False
|
|
||||||
|
|
||||||
if load_module or load_underscore:
|
if load_module or load_underscore:
|
||||||
return super(OETestLoader, self).loadTestsFromModule(
|
return super(OETestLoader, self).loadTestsFromModule(
|
||||||
|
|||||||
Reference in New Issue
Block a user