From: Colin Watson <cjwatson@debian.org>
Date: Wed, 31 Jul 2024 12:02:40 +0100
Subject: Use importlib rather than imp.load_source

The `imp` module was removed in Python 3.12.  Recipe from
https://docs.python.org/3/whatsnew/3.12.html#imp.
---
 runtests.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/runtests.py b/runtests.py
index 19a7ef3..b681c91 100755
--- a/runtests.py
+++ b/runtests.py
@@ -13,7 +13,9 @@ found test suites into one big test suite and run them all at once.
 * Modified to use os.path.walk to find all the test scripts
 * Modified to find all python scripts, not just ones of the form *test.py
 """
-import sys, os, re, unittest, imp
+import sys, os, re, unittest
+import importlib.machinery
+import importlib.util
 
 import logging
 rootLogger = logging.getLogger ()
@@ -31,6 +33,16 @@ def path_visitor(files, dirname, names):
 	for name in names:
 		files.append(os.path.join(dirname, name))
 
+def load_source(modname, filename):
+	loader = importlib.machinery.SourceFileLoader (modname, filename)
+	spec = importlib.util.spec_from_file_location (modname, filename, loader=loader)
+	module = importlib.util.module_from_spec (spec)
+	# The module is always executed and not cached in sys.modules.
+	# Uncomment the following line to cache the module.
+	# sys.modules[module.__name__] = module
+	loader.exec_module (module)
+	return module
+
 def regressionTest():
 	#Find all the files to run
 	files = []
@@ -44,7 +56,7 @@ def regressionTest():
 	modules = []
 	modCount = 1
 	for filename in files:
-		modules.append (imp.load_source ("TestModule%s" % str (modCount), filename))
+		modules.append (load_source ("TestModule%s" % str (modCount), filename))
 		modCount += 1
 	#modules = map(__import__, moduleNames)
 	load = unittest.defaultTestLoader.loadTestsFromModule
