Skip to content

Commit 1946abd

Browse files
committed
Add test
1 parent 30a34dd commit 1946abd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Lib/test/test_concurrent_futures/test_interpreter_pool.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import contextlib
33
import io
44
import os
5+
import subprocess
56
import sys
7+
import textwrap
68
import time
79
import unittest
810
from concurrent.futures.interpreter import BrokenInterpreterPool
@@ -457,6 +459,38 @@ def test_free_reference(self):
457459
# Weak references don't cross between interpreters.
458460
raise unittest.SkipTest('not applicable')
459461

462+
def test_import_interpreter_pool_executor(self):
463+
# Test the import behavior normally if _interpreters is unavailable.
464+
code = textwrap.dedent(f"""
465+
from concurrent import futures
466+
import sys
467+
# Set it to None to emulate the case when _interpreter is unavailable.
468+
futures._interpreters = None
469+
470+
try:
471+
futures.InterpreterPoolExecutor
472+
except AttributeError:
473+
pass
474+
else:
475+
print('AttributeError not raised!', file=sys.stderr)
476+
sys.exit(1)
477+
478+
try:
479+
from concurrent.futures import InterpreterPoolExecutor
480+
except ImportError:
481+
pass
482+
else:
483+
print('ImportError not raised!', file=sys.stderr)
484+
sys.exit(1)
485+
486+
487+
from concurrent.futures import *
488+
""")
489+
490+
cmd = [sys.executable, '-c', code]
491+
p = subprocess.run(cmd, capture_output=True)
492+
self.assertEqual(p.returncode, 0, p.stderr.decode())
493+
460494

461495
class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase):
462496

0 commit comments

Comments
 (0)