From efd45b195a976fed1b783d5997fc65f2f8e2d383 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Tue, 20 Jun 2023 12:38:23 -0400 Subject: [PATCH] More importlib find_module migration Do not use importlib find_module API in bazel/_gevent_test_main.py This API was removed in Python 3.12 (https://github.com/python/cpython/issues/98040). --- bazel/_gevent_test_main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bazel/_gevent_test_main.py b/bazel/_gevent_test_main.py index f7936daaf0db3..bec31a911b6bb 100644 --- a/bazel/_gevent_test_main.py +++ b/bazel/_gevent_test_main.py @@ -42,6 +42,7 @@ import sys import os import pkgutil +import importlib def trace_callback(event, args): if event in ("switch", "throw"): @@ -73,7 +74,9 @@ def __init__(self, pattern: str): tests = [] for importer, module_name, is_package in pkgutil.walk_packages([os.path.dirname(os.path.relpath(__file__))]): if pattern in module_name: - module = importer.find_module(module_name).load_module(module_name) + spec = importer.find_spec(module_name) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) tests.append(loader.loadTestsFromModule(module)) if len(tests) != 1: raise AssertionError("Expected only 1 test module. Found {}".format(tests))