Skip to content

Commit

Permalink
Port runtests.py to Python 3.12
Browse files Browse the repository at this point in the history
Don't use removed importlib load_modules() method.

See: python/cpython#104212
  • Loading branch information
vstinner committed May 24, 2023
1 parent 0a030e3 commit c4610a5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Run Tulip unittests.
"""Run tests.
Usage:
python3 runtests.py [flags] [pattern] ...
Expand All @@ -20,7 +20,6 @@

# Originally written by Beech Horn (for NDB).

from __future__ import print_function
import gc
import importlib.machinery
import logging
Expand All @@ -29,6 +28,7 @@
import re
import sys
import textwrap
import types
import unittest.signals

from hachoir.test import setup_tests
Expand Down Expand Up @@ -69,9 +69,13 @@
help='optional regex patterns to match test ids (default all tests)')


def load_module(modname, sourcefile):
loader = importlib.machinery.SourceFileLoader(modname, sourcefile)
return loader.load_module()
def load_module(module_name, filename):
loader = importlib.machinery.SourceFileLoader(module_name, filename)
module = types.ModuleType(loader.name)
module.__file__ = filename
sys.modules[module.__name__] = module
loader.exec_module(module)
return module


def load_modules(basedir, suffix='.py'):
Expand Down

0 comments on commit c4610a5

Please sign in to comment.