]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-152548: Add a test.support.isolation.runInSubprocess() decorator (GH-152551)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 27 Jul 2026 19:02:59 +0000 (22:02 +0300)
committerGitHub <noreply@github.com>
Mon, 27 Jul 2026 19:02:59 +0000 (19:02 +0000)
commitbde526d7be55014ec49fd44b831c948664ce508b
tree4abe5b6d357cbadddbf0fb98ccf73ed5e01b4409
parentb099df5f177e43ebefde24a6714729277aa1bf8c
gh-152548: Add a test.support.isolation.runInSubprocess() decorator (GH-152551)

Run a test in a fresh interpreter subprocess, so that it does not share global
or interpreter state with the rest of the test run.  It can decorate a test
method (only that method runs in a subprocess) or a TestCase subclass (the
whole class runs in one subprocess, with its setUpClass()/setUp()/tearDown()/
tearDownClass() running there rather than in the parent).

Failures, errors and skips, including those of individual subtests, are
reported for the test; a failure or an error shows the original subprocess
traceback.  The subprocess inherits the parent's resource, memory, verbosity
and failfast configuration, so that requires_resource(), bigmemtest() and
similar behave the same in both processes.  A decorated test is skipped where
subprocesses are unavailable, since it must spawn one.

The test.support.isolation.runningInSubprocess flag is true in the subprocess,
so that fixtures can choose what to run there.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Doc/library/test.rst
Lib/test/_isolated_sample.py [new file with mode: 0644]
Lib/test/support/isolation.py [new file with mode: 0644]
Lib/test/support/subprocess_runner.py [new file with mode: 0644]
Lib/test/test_support.py
Misc/NEWS.d/next/Tests/2026-06-29-10-14-09.gh-issue-152548.Khw9J7.rst [new file with mode: 0644]