Skip to contentSkip to conversation

oeqa/core/loader.py: Do not import underscore modules by default

PATCH New [email protected] 1 participant 2 messages Mar 27, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover oeqa/core/loader.py: Do not import underscore modules by default

From: Mariano Lopez <[email protected]>

Changes in v2:
- Rebase to master.
- Fix how bug number was specified to make patchtest happy.

The following changes since commit f5187871ce03fc24cb0017cff1089a288f50a24f:

classes: Replace "if test" file tests with POSIX file tests (2017-03-27 11:08:34 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib mariano/bug10980
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=mariano/bug10980

Mariano Lopez (1):
oeqa/core/loader.py: Do not import underscore modules by default

 meta/lib/oeqa/core/loader.py | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)
Signature · 1 line
2.10.2
#1 lore raw

PATCH v2 1/1 oeqa/core/loader.py: Do not import underscore modules by default

From: Mariano Lopez <[email protected]>

Underscore modules are meant to be run only when manually added to the test suite, so far another mechanisms are in place to make this happen with runtime, sdk, and esdk (mostly in test* bbclasses).

This will add such functionality in the core framework so other specific frameworks can take use this without adding something else.

[YOCTO #10980]

---
 meta/lib/oeqa/core/loader.py | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)
meta/lib/oeqa/core/loader.py +30 -4
index 74f1117..63a1703 100644
@@ -223,8 +223,21 @@ class OETestLoader(unittest.TestLoader):
                 msg = 'Tried to import %s test module but is a built-in'
                 raise ImportError(msg % module.__name__)
 
-            if not self.modules or "all" in self.modules or \
-                    module.__name__ in self.modules:
+            # 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:
                 return super(OETestLoader, self).loadTestsFromModule(
                         module, *args, pattern=pattern, **kws)
             else:
@@ -238,8 +251,21 @@ class OETestLoader(unittest.TestLoader):
                 msg = 'Tried to import %s test module but is a built-in'
                 raise ImportError(msg % module.__name__)
 
-            if not self.modules or "all" in self.modules or \
-                    module.__name__ in self.modules:
+            # 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:
                 return super(OETestLoader, self).loadTestsFromModule(
                         module, use_load_tests)
             else:
Signature · 1 line
2.10.2