Hi,
As I saw Nathan add note about DeprecationWarning in run_test.py on
Subversion's Python 3 Support Status page yesterday, I've made a patch
to avoid warning.
I didn't read context around the code changed, I only rewrited it as the
example code[1] do.
[1]
https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
I've run it on Python 3.7.1 and it seems it can run Python test units
without DeprecationWarning.
Could anyone review this?
Thanks,
--
Yasuhito FUTATSUKI <[email protected]> / <[email protected]>
Index: build/run_tests.py
===================================================================
--- build/run_tests.py (revision 1872242)
+++ build/run_tests.py (working copy)
@@ -50,7 +50,7 @@
import os, sys, shutil, codecs
import re
import logging
-import optparse, subprocess, imp, threading, traceback
+import optparse, subprocess, threading, traceback
from datetime import datetime
try:
@@ -64,6 +64,11 @@
# Python >= 3.0 already has this build in
import exceptions
+if sys.version_info < (3, 5):
+ import imp
+else:
+ import importlib.util
+
# Ensure the compiled C tests use a known locale (Python tests set the locale
# explicitly).
os.environ['LC_ALL'] = 'C'
@@ -821,10 +826,15 @@
if sys.version_info < (3, 0):
prog_mod = imp.load_module(progbase[:-3], open(progabs, 'r'), progabs,
('.py', 'U', imp.PY_SOURCE))
- else:
+ elif sys.version_info < (3, 5):
prog_mod = imp.load_module(progbase[:-3],
open(progabs, 'r', encoding="utf-8"),
progabs, ('.py', 'U', imp.PY_SOURCE))
+ else:
+ spec = importlib.util.spec_from_file_location(progbase[:-3], progabs)
+ prog_mod = importlib.util.module_from_spec(spec)
+ sys.modules[progbase[:-3]] = prog_mod
+ spec.loader.exec_module(prog_mod)
except:
print("\nError loading test (details in following traceback): " +
progbase)
traceback.print_exc()