|
9 | 9 | import builtins |
10 | 10 | import unittest |
11 | 11 | import unittest.mock |
| 12 | +import os |
12 | 13 | import re |
13 | 14 | import tempfile |
14 | 15 | import random |
|
19 | 20 | import shutil |
20 | 21 | from test.support import (Error, captured_output, cpython_only, ALWAYS_EQ, |
21 | 22 | requires_debug_ranges, has_no_debug_ranges, |
22 | | - requires_subprocess) |
| 23 | + requires_subprocess, os_helper) |
23 | 24 | from test.support.os_helper import TESTFN, temp_dir, unlink |
24 | 25 | from test.support.script_helper import assert_python_ok, assert_python_failure, make_script |
25 | 26 | from test.support.import_helper import forget |
@@ -5220,6 +5221,23 @@ def test_find_incompatible_extension_modules(self): |
5220 | 5221 | 'If this is a false positive, define SHLIB_SUFFIX in sysconfig.' |
5221 | 5222 | )) |
5222 | 5223 |
|
| 5224 | + @unittest.skipIf(not importlib.machinery.EXTENSION_SUFFIXES, 'Platform does not support extension modules') |
| 5225 | + def test_incompatible_extension_modules_hint(self): |
| 5226 | + untagged_suffix = importlib.machinery.EXTENSION_SUFFIXES[-1] |
| 5227 | + with os_helper.temp_dir() as tmp: |
| 5228 | + # create a module with a incompatible ABI tag |
| 5229 | + incompatible_module = os.path.join(tmp, f'foo.some-abi{untagged_suffix}') |
| 5230 | + open(incompatible_module, "wb").close() |
| 5231 | + # try importing it |
| 5232 | + code = f''' |
| 5233 | + import sys |
| 5234 | + sys.path.insert(0, {tmp!r}) |
| 5235 | + import foo |
| 5236 | + ''' |
| 5237 | + _, _, stderr = assert_python_failure('-c', code, __cwd=tmp) |
| 5238 | + hint = b'Although a module with this name was found for a different Python version (some-abi).' |
| 5239 | + self.assertIn(hint, stderr) |
| 5240 | + |
5223 | 5241 |
|
5224 | 5242 | class TestColorizedTraceback(unittest.TestCase): |
5225 | 5243 | maxDiff = None |
|
0 commit comments