Skip to content

Commit 4aa316a

Browse files
gh-152548: Skip isolated() tests without subprocess support
@isolated() always runs the test in a subprocess, so skip it in the parent process on platforms that lack subprocess support, the same way the tests it replaces were guarded by requires_subprocess(). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent bcc35ee commit 4aa316a

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

Doc/library/test.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,8 @@ The :mod:`!test.support` module defines the following functions:
996996
:func:`requires_resource`, :func:`requires`, :func:`bigmemtest` and the like
997997
behave consistently in both processes.
998998

999+
The test is skipped on platforms without subprocess support.
1000+
9991001

10001002
.. data:: running_isolated
10011003

Lib/test/support/_isolation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ def _remote(detail):
8181
return _RemoteTraceback('\n"""\n%s"""' % detail)
8282

8383

84+
def _check_subprocess_support():
85+
# isolated() always runs the test in a subprocess, so skip (in the parent)
86+
# on platforms that do not support spawning one.
87+
import test.support as support
88+
if not support.has_subprocess_support:
89+
raise unittest.SkipTest('requires subprocess support')
90+
91+
8492
def _run_in_subprocess(module, qualname):
8593
"""Run module.qualname (a test method or class) in a fresh subprocess.
8694
@@ -155,6 +163,7 @@ def wrapper(self, /, *args, **kwargs):
155163
if running_isolated:
156164
# Already running in the subprocess: run the real test.
157165
return func(self, *args, **kwargs)
166+
_check_subprocess_support()
158167
cls = type(self)
159168
qualname = f'{cls.__qualname__}.{func.__name__}'
160169
outcomes, output, returncode = _run_in_subprocess(cls.__module__,
@@ -177,6 +186,7 @@ def setUpClass(cls):
177186
if running_isolated:
178187
orig_setUpClass(cls)
179188
return
189+
_check_subprocess_support()
180190
# Run the whole class in a single subprocess and stash the outcomes
181191
# for the wrapped test methods to replay.
182192
outcomes, output, returncode = _run_in_subprocess(cls.__module__,
@@ -243,6 +253,8 @@ def isolated():
243253
skipped are reported individually. The original subprocess traceback is
244254
shown as the cause of a reported failure or error. Use
245255
:data:`running_isolated` in fixtures to choose what to run in the subprocess.
256+
257+
The test is skipped on platforms without subprocess support.
246258
"""
247259
def decorator(obj):
248260
if isinstance(obj, type):

0 commit comments

Comments
 (0)