Skip to content

Commit 44c765f

Browse files
committed
Add test_incompatible_extension_modules_hint
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent 1e1bc55 commit 44c765f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Lib/test/test_traceback.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import builtins
1010
import unittest
1111
import unittest.mock
12+
import os
1213
import re
1314
import tempfile
1415
import random
@@ -19,7 +20,7 @@
1920
import shutil
2021
from test.support import (Error, captured_output, cpython_only, ALWAYS_EQ,
2122
requires_debug_ranges, has_no_debug_ranges,
22-
requires_subprocess)
23+
requires_subprocess, os_helper)
2324
from test.support.os_helper import TESTFN, temp_dir, unlink
2425
from test.support.script_helper import assert_python_ok, assert_python_failure, make_script
2526
from test.support.import_helper import forget
@@ -5220,6 +5221,23 @@ def test_find_incompatible_extension_modules(self):
52205221
'If this is a false positive, define SHLIB_SUFFIX in sysconfig.'
52215222
))
52225223

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+
52235241

52245242
class TestColorizedTraceback(unittest.TestCase):
52255243
maxDiff = None

0 commit comments

Comments
 (0)