Skip to content

Commit 0696314

Browse files
committed
test: add import tests
1 parent 25f8710 commit 0696314

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

tests/concurrent/test_subinterpreters.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# ==============================================================================
1515

1616
import atexit
17+
import importlib
18+
import re
1719
import sys
1820

1921
import pytest
@@ -26,10 +28,16 @@
2628
)
2729

2830

29-
if PYPY or WASM or sys.version_info < (3, 14):
31+
if (
32+
PYPY
33+
or WASM
34+
or sys.version_info < (3, 14)
35+
or not getattr(sys.implementation, 'supports_isolated_interpreters', False)
36+
):
3037
pytest.skip('Test for CPython 3.14+ only', allow_module_level=True)
3138

3239

40+
from concurrent import interpreters
3341
from concurrent.futures import InterpreterPoolExecutor, as_completed
3442

3543

@@ -64,3 +72,29 @@ def concurrent_run(func, /, *args, **kwargs):
6472

6573

6674
run(object) # warm-up
75+
76+
77+
def test_import_failure():
78+
sub_interpreter = interpreters.create()
79+
80+
with pytest.raises(
81+
ImportError,
82+
match=re.escape('module optree._C does not support loading in subinterpreters'),
83+
) as excinfo:
84+
run(importlib.import_module, 'optree')
85+
86+
with pytest.raises(
87+
interpreters.ExecutionFailed,
88+
match=re.escape('module optree._C does not support loading in subinterpreters'),
89+
) as excinfo:
90+
sub_interpreter.call(importlib.import_module, 'optree')
91+
assert excinfo.value.excinfo.type.__name__ == 'ImportError'
92+
93+
with pytest.raises(
94+
interpreters.ExecutionFailed,
95+
match=re.escape('module optree._C does not support loading in subinterpreters'),
96+
) as excinfo:
97+
sub_interpreter.exec('import optree')
98+
assert excinfo.value.excinfo.type.__name__ == 'ImportError'
99+
100+
sub_interpreter.close()

0 commit comments

Comments
 (0)