Skip to content

Commit

Permalink
More importlib find_module migration
Browse files Browse the repository at this point in the history
Do not use importlib find_module API in bazel/_gevent_test_main.py

This API was removed in Python 3.12
(python/cpython#98040).
  • Loading branch information
musicinmybrain committed Jul 17, 2023
1 parent 095ddf0 commit efd45b1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bazel/_gevent_test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import sys
import os
import pkgutil
import importlib

def trace_callback(event, args):
if event in ("switch", "throw"):
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit efd45b1

Please sign in to comment.