From a6cb711e1cb6a985ae61560495a5546fd36a0df0 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 16 Sep 2021 16:02:14 +0200 Subject: [PATCH] test: use importlib instead of imp Replace the usage of `imp` with `importlib` because the former is deprecated and newer pylint will complain and break CI. --- test/unit/plugintest.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/unit/plugintest.py b/test/unit/plugintest.py index 202bf4e..22305e3 100644 --- a/test/unit/plugintest.py +++ b/test/unit/plugintest.py @@ -3,7 +3,7 @@ # -import imp +import importlib import os import unittest @@ -29,13 +29,12 @@ class PluginTest(unittest.TestCase): return None root = os.getenv("GITHUB_WORKSPACE", os.getcwd()) - haystack = os.path.join(root, "plugins", plugin_type) - fp, path, desc = imp.find_module("osbuild", [haystack]) - - try: - return imp.load_module("osbuild", fp, path, desc) - finally: - fp.close() + haystack = os.path.join(root, "plugins", plugin_type, "osbuild.py") + spec = importlib.util.spec_from_file_location("osbuild", haystack) + assert spec, f"Could not find '{plugin_type}' plugin" + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module def setUp(self): """Setup plugin testing environment