|
32 | 32 | # Windows uses MSVC compiler |
33 | 33 | MSVC = (os.name == "nt") |
34 | 34 |
|
35 | | -TESTS = [ |
36 | | - ("test_pythoncapi_compat_cext", "C"), |
37 | | -] |
| 35 | +# C++ is only supported on Python 3.6 and newer |
| 36 | +TEST_CXX = (sys.version_info >= (3, 6)) |
| 37 | + |
38 | 38 | if not MSVC: |
39 | | - TESTS.extend(( |
| 39 | + C_TESTS = [ |
| 40 | + ("test_pythoncapi_compat_cext_c99", "C99"), |
| 41 | + ("test_pythoncapi_compat_cext_c11", "C11"), |
| 42 | + ] |
| 43 | + CXX_TESTS = [ |
40 | 44 | ("test_pythoncapi_compat_cpp03ext", "C++03"), |
41 | 45 | ("test_pythoncapi_compat_cpp11ext", "C++11"), |
42 | | - )) |
| 46 | + ("test_pythoncapi_compat_cpp14ext", "C++14"), |
| 47 | + ("test_pythoncapi_compat_cpp17ext", "C++17"), |
| 48 | + ("test_pythoncapi_compat_cpp20ext", "C++20"), |
| 49 | + ] |
43 | 50 | else: |
44 | | - TESTS.extend(( |
| 51 | + C_TESTS = [ |
| 52 | + ("test_pythoncapi_compat_cext_c11", "C11"), |
| 53 | + ] |
| 54 | + CXX_TESTS = [ |
45 | 55 | ("test_pythoncapi_compat_cppext", "C++"), |
46 | 56 | ("test_pythoncapi_compat_cpp14ext", "C++14"), |
47 | | - )) |
| 57 | + ] |
48 | 58 |
|
49 | 59 |
|
50 | 60 | VERBOSE = False |
@@ -84,9 +94,12 @@ def import_tests(module_name): |
84 | 94 |
|
85 | 95 | if not pythonpath: |
86 | 96 | raise Exception("Failed to find the build directory") |
87 | | - sys.path.append(pythonpath) |
88 | | - |
89 | | - return __import__(module_name) |
| 97 | + old_sys_path = list(sys.path) |
| 98 | + try: |
| 99 | + sys.path.append(pythonpath) |
| 100 | + return __import__(module_name) |
| 101 | + finally: |
| 102 | + sys.path[:] = old_sys_path |
90 | 103 |
|
91 | 104 |
|
92 | 105 | def _run_tests(tests, verbose): |
@@ -155,18 +168,7 @@ def run_tests(module_name, lang): |
155 | 168 | title = "Test %s (%s)" % (module_name, lang) |
156 | 169 | display_title(title) |
157 | 170 |
|
158 | | - try: |
159 | | - testmod = import_tests(module_name) |
160 | | - except ImportError: |
161 | | - # The C extension must always be available |
162 | | - if lang == "C": |
163 | | - raise |
164 | | - |
165 | | - if VERBOSE: |
166 | | - print("%s: skip %s, missing %s extension" |
167 | | - % (python_version(), lang, module_name)) |
168 | | - print() |
169 | | - return |
| 171 | + testmod = import_tests(module_name) |
170 | 172 |
|
171 | 173 | if VERBOSE: |
172 | 174 | empty_line = False |
@@ -226,7 +228,10 @@ def main(): |
226 | 228 |
|
227 | 229 | build_ext() |
228 | 230 |
|
229 | | - for module_name, lang in TESTS: |
| 231 | + tests = list(C_TESTS) |
| 232 | + if TEST_CXX: |
| 233 | + tests += CXX_TESTS |
| 234 | + for module_name, lang in tests: |
230 | 235 | run_tests(module_name, lang) |
231 | 236 |
|
232 | 237 |
|
|
0 commit comments