Skip to contentSkip to conversation

OEQA loader improvment

PATCH New [email protected] 1 participant 3 messages Feb 27, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover OEQA loader improvment

From: Mariano Lopez <[email protected]>

The first adds more verbosity when a class doesn't inherit from the expected test class.

The second patch raises an error when trying to import a test with the same module name as a built-in module.

Change in v2:

- Rebased to current master

The following changes since commit 3c83b56309ab419f8cda72c0711479f60f61439a:

bitbake: fetch2/svn: change 'rsh' parameter to 'ssh' (2017-02-23 12:50:17 -0800)

are available in the git repository at:

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

Mariano Lopez (2):
oeqa/core/loader.py: Give meaningful error when failed to load classes oeqa/core/loader.py: Avoid importing tests with built-ins name

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

PATCH v2 1/2 oeqa/core/loader.py: Give meaningful error when failed to load classes

From: Mariano Lopez <[email protected]>

With this we get the class that is actually having the problem, not just a TypeError with an unknown class causing the error.

---
 meta/lib/oeqa/core/loader.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
meta/lib/oeqa/core/loader.py +4 -4
index a380325..b9ba923 100644
@@ -171,11 +171,11 @@ class OETestLoader(unittest.TestLoader):
         """
         if issubclass(testCaseClass, unittest.suite.TestSuite):
             raise TypeError("Test cases should not be derived from TestSuite." \
-                                " Maybe you meant to derive from TestCase?")
+                                " Maybe you meant to derive %s from TestCase?" \
+                                % testCaseClass.__name__)
         if not issubclass(testCaseClass, self.caseClass):
-            raise TypeError("Test cases need to be derived from %s" % \
-                    self.caseClass.__name__)
-
+            raise TypeError("Test %s is not derived from %s" % \
+                    (testCaseClass.__name__, self.caseClass.__name__))
 
         testCaseNames = self.getTestCaseNames(testCaseClass)
         if not testCaseNames and hasattr(testCaseClass, 'runTest'):
Signature · 1 line
2.6.6
#2 lore raw

PATCH v2 2/2 oeqa/core/loader.py: Avoid importing tests with built-ins name

In reply to [email protected]

From: Mariano Lopez <[email protected]>

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]

---
 meta/lib/oeqa/core/loader.py | 11 +++++++++++
 1 file changed, 11 insertions(+)
meta/lib/oeqa/core/loader.py +11 -0
index b9ba923..74f1117 100644
@@ -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(
Signature · 1 line
2.6.6