Skip to content

Commit 3e6b328

Browse files
[3.12] gh-112503: Fix test_sys on WASI (gh-112505)
Skip tests if no interpreters module.gh-110713 added some tests that use the interpreters module but did not accommodated builds that don't support subinterpreters (incl. an interpreters module). We fix that here by catching ImportError and skipping tests as appropriate.
1 parent 5b6858c commit 3e6b328

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Lib/test/test_sys.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@
1515
from test.support.script_helper import assert_python_ok, assert_python_failure
1616
from test.support import threading_helper
1717
from test.support import import_helper
18-
from test.support import interpreters
1918
import textwrap
2019
import unittest
2120
import warnings
2221

22+
try:
23+
from test.support import interpreters
24+
except ImportError:
25+
interpreters = None
26+
27+
28+
def requires_subinterpreters(func):
29+
deco = unittest.skipIf(interpreters is None,
30+
'Test requires subinterpreters')
31+
return deco(func)
32+
2333

2434
DICT_KEY_STRUCT_FORMAT = 'n2BI2n'
2535

@@ -700,6 +710,7 @@ def __hash__(self):
700710

701711
self.assertRaises(TypeError, sys.intern, S("abc"))
702712

713+
@requires_subinterpreters
703714
def test_subinterp_intern_dynamically_allocated(self):
704715
s = "never interned before" + str(random.randrange(0, 10**9))
705716
t = sys.intern(s)
@@ -713,6 +724,7 @@ def test_subinterp_intern_dynamically_allocated(self):
713724
assert id(t) != {id(t)}, (id(t), {id(t)})
714725
'''))
715726

727+
@requires_subinterpreters
716728
def test_subinterp_intern_statically_allocated(self):
717729
# See Tools/build/generate_global_objects.py for the list
718730
# of strings that are always statically allocated.

0 commit comments

Comments
 (0)