]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa/core/loader.py: Avoid importing tests with built-ins name
authorMariano Lopez <mariano.lopez@linux.intel.com>
Mon, 27 Feb 2017 07:45:01 +0000 (07:45 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 1 Mar 2017 15:50:19 +0000 (15:50 +0000)
If importing a test with the same name as a built-in module,
it will silently import the built-in and check for tests in
built-in module. This happened with syslog module in debian
based machines, so add a raise to avoid this behavior.

[YOCTO #10978]

Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/lib/oeqa/core/loader.py

index b9ba9235af88e948dcc50c2dcbc56cb133e4eaa5..74f1117825c1b1a9210665e8332a9afae1331e88 100644 (file)
@@ -216,6 +216,13 @@ class OETestLoader(unittest.TestLoader):
     # use_load_tests deprecation via *args and **kws.  See issue 16662.
     if sys.version_info >= (3,5):
         def loadTestsFromModule(self, module, *args, pattern=None, **kws):
+            """
+                Returns a suite of all tests cases contained in 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__)
+
             if not self.modules or "all" in self.modules or \
                     module.__name__ in self.modules:
                 return super(OETestLoader, self).loadTestsFromModule(
@@ -227,6 +234,10 @@ class OETestLoader(unittest.TestLoader):
             """
                 Returns a suite of all tests cases contained in 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__)
+
             if not self.modules or "all" in self.modules or \
                     module.__name__ in self.modules:
                 return super(OETestLoader, self).loadTestsFromModule(