From bff8d4137057c9bc37436b8df29d86a3c2584938 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 16 Aug 2021 09:54:06 +0900 Subject: [PATCH] Use importlib instead of imp ... because the imp module is deprecated since Python 3.4 . Closes-Bug: #1937904 Change-Id: Ia3f83df336fd243c25f7471d56a44370c11bb5e1 --- novaclient/tests/unit/test_discover.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/novaclient/tests/unit/test_discover.py b/novaclient/tests/unit/test_discover.py index d5fa54000..f294e2e81 100644 --- a/novaclient/tests/unit/test_discover.py +++ b/novaclient/tests/unit/test_discover.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import imp +import importlib import inspect from unittest import mock @@ -31,7 +31,8 @@ class DiscoverTest(utils.TestCase): def mock_mgr(): fake_ep = mock.Mock() fake_ep.name = 'foo' - fake_ep.module = imp.new_module('foo') + module_spec = importlib.machinery.ModuleSpec('foo', None) + fake_ep.module = importlib.util.module_from_spec(module_spec) fake_ep.load.return_value = fake_ep.module fake_ext = extension.Extension( name='foo', @@ -52,10 +53,14 @@ class DiscoverTest(utils.TestCase): def test_discover_extensions(self): def mock_discover_via_python_path(): - yield 'foo', imp.new_module('foo') + module_spec = importlib.machinery.ModuleSpec('foo', None) + module = importlib.util.module_from_spec(module_spec) + yield 'foo', module def mock_discover_via_entry_points(): - yield 'baz', imp.new_module('baz') + module_spec = importlib.machinery.ModuleSpec('baz', None) + module = importlib.util.module_from_spec(module_spec) + yield 'baz', module @mock.patch.object(client, '_discover_via_python_path',