]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa/runtime: load modules using importlib
authorRoss Burton <ross@burtonini.com>
Wed, 20 Oct 2021 17:30:06 +0000 (18:30 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 3 Nov 2021 11:17:55 +0000 (11:17 +0000)
Instead of using __import__() which is low-level and discouraged, use
importlib.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 9f501d22eab5dbd565f3f5783f4f484a6d1f70a2)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
meta/lib/oeqa/runtime/context.py

index 3826f2764216bd4bcca302cb8be2d53b22feef96..7908ce1fd4633da626ce5f898916e8dcd13625f1 100644 (file)
@@ -175,16 +175,12 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
     # Search for and return a controller or None from given module name
     @staticmethod
     def _loadControllerFromModule(target, modulename):
-        obj = None
-        # import module, allowing it to raise import exception
-        module = __import__(modulename, globals(), locals(), [target])
-        # look for target class in the module, catching any exceptions as it
-        # is valid that a module may not have the target class.
         try:
-            obj = getattr(module, target)
-        except:
-            obj = None
-        return obj
+            import importlib
+            module = importlib.import_module(modulename)
+            return getattr(module, target)
+        except AttributeError:
+            return None
 
     @staticmethod
     def readPackagesManifest(manifest):