tests: Replace removed SourceFileLoader.load_module() Python 3.15 removed importlib's load_module(), so run_tests.py fails: AttributeError: 'SourceFileLoader' object has no attribute 'load_module'. Did you mean '.exec_module' instead of '.load_module'? Load the tests package with spec_from_file_location() and exec_module() instead. Register it in sys.modules before executing, as load_module() did, since the package imports its submodules relative to 'tests'. Reviewed-by: Firas Jahjah <firasj@amazon.com> Reviewed-by: Yonatan Nachum <ynachum@amazon.com> Signed-off-by: Michael Margolin <mrgolin@amazon.com>
diff --git a/tests/run_tests.py b/tests/run_tests.py index 9d7edf2..318d152 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py
@@ -3,12 +3,16 @@ # Copyright (c) 2018, Mellanox Technologies. All rights reserved. See COPYING file from args_parser import parser +import importlib.util import unittest +import sys import os -from importlib.machinery import SourceFileLoader module_path = os.path.join(os.path.dirname(__file__), '__init__.py') -tests = SourceFileLoader('tests', module_path).load_module() +spec = importlib.util.spec_from_file_location('tests', module_path) +tests = importlib.util.module_from_spec(spec) +sys.modules['tests'] = tests +spec.loader.exec_module(tests) parser.parse_args() unittest.main(module=tests)