From 66f9abdc761d61a1b0919f165be669a49c95fe8c Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Thu, 12 Dec 2019 18:15:23 +0100 Subject: [PATCH] Import importlib directly Now that we support Python 3.x only wwe can import importlib directly. Change-Id: Ifc93760522d68871b5a1a5b51bac10c40abd8448 --- .../unit/api/controllers/v1/test_expose.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/ironic/tests/unit/api/controllers/v1/test_expose.py b/ironic/tests/unit/api/controllers/v1/test_expose.py index 183a5c8937..eee02036d7 100644 --- a/ironic/tests/unit/api/controllers/v1/test_expose.py +++ b/ironic/tests/unit/api/controllers/v1/test_expose.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from importlib import machinery import inspect import os import sys @@ -44,20 +45,8 @@ class TestExposedAPIMethodsCheckPolicy(test_base.TestCase): def _test(self, module): module_path = os.path.abspath(sys.modules[module].__file__) - # (rpittau) we can use importlib only with python >= 3.3 - # we can remove the if-else block once python 2.x is gone - if sys.version_info[:2] >= (3, 3): - from importlib.machinery import SourceFileLoader - SourceFileLoader(uuidutils.generate_uuid(), - module_path).load_module() - else: - import imp - # NOTE(vdrok): coverage runs on compiled .pyc files, which breaks - # load_source. Strip c and o letters from the end of the module - # path, just in case someone tries to use .pyo or .pyc for whatever - # reason - imp.load_source(uuidutils.generate_uuid(), - module_path.rstrip('co')) + machinery.SourceFileLoader(uuidutils.generate_uuid(), + module_path).load_module() for func in self.exposed_methods: src = inspect.getsource(func)