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.
This commit is contained in:
Christian Kellner 2021-09-16 16:02:14 +02:00 committed by Ondřej Budai
parent 98142d3325
commit a6cb711e1c

View file

@ -3,7 +3,7 @@
# #
import imp import importlib
import os import os
import unittest import unittest
@ -29,13 +29,12 @@ class PluginTest(unittest.TestCase):
return None return None
root = os.getenv("GITHUB_WORKSPACE", os.getcwd()) root = os.getenv("GITHUB_WORKSPACE", os.getcwd())
haystack = os.path.join(root, "plugins", plugin_type) haystack = os.path.join(root, "plugins", plugin_type, "osbuild.py")
fp, path, desc = imp.find_module("osbuild", [haystack]) spec = importlib.util.spec_from_file_location("osbuild", haystack)
assert spec, f"Could not find '{plugin_type}' plugin"
try: module = importlib.util.module_from_spec(spec)
return imp.load_module("osbuild", fp, path, desc) spec.loader.exec_module(module)
finally: return module
fp.close()
def setUp(self): def setUp(self):
"""Setup plugin testing environment """Setup plugin testing environment