From 33970fcc6b8f4cffe116d66cee8a94e19e743937 Mon Sep 17 00:00:00 2001 From: zhoulinhui Date: Sun, 30 Aug 2020 00:34:27 +0800 Subject: Update imp module to importlib The imp module is deprecated[1] since version 3.4, use importlib to instead 1: https://docs.python.org/3/library/imp.html Change-Id: I79dfd923531dd3e00d23e1682865f56f0cf437d2 --- tests/test_set_config.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_set_config.py b/tests/test_set_config.py index 3888a38cc..1f49edc3c 100644 --- a/tests/test_set_config.py +++ b/tests/test_set_config.py @@ -11,7 +11,7 @@ # limitations under the License. import copy -import imp +import importlib.util import json import os.path import sys @@ -19,13 +19,23 @@ from unittest import mock from oslotest import base + +def load_module(name, path): + module_spec = importlib.util.spec_from_file_location( + name, path + ) + module = importlib.util.module_from_spec(module_spec) + module_spec.loader.exec_module(module) + return module + + # nasty: to import set_config (not a part of the kolla package) this_dir = os.path.dirname(sys.modules[__name__].__file__) set_configs_file = os.path.abspath( os.path.join(this_dir, '..', 'docker', 'base', 'set_configs.py')) -set_configs = imp.load_source('set_configs', set_configs_file) +set_configs = load_module('set_configs', set_configs_file) class LoadFromFile(base.BaseTestCase): -- cgit v1.2.3