Repository navigation
Add a decorator to run a test in an isolated subprocess #152548
Copy link
Copy link
Open
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-featureA feature request or enhancementA feature request or enhancement
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancementtestsTests in the Lib/test dirTests in the Lib/test dir
on Jun 29, 2026 - added 10 commits that reference this issue
on Jun 29, 2026 - added 3 commits that reference this issue
on Jul 27, 2026 7 remaining items
- added 5 commits that reference this issue
on Jul 28, 2026 - added 3 commits that reference this issue
on Aug 5, 2026 - added 3 commits that reference this issue
on Oct 9, 2026
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-featureA feature request or enhancementA feature request or enhancement
Feature or enhancement
Some tests need to run in a fresh interpreter, isolated from the rest of the test run: they mutate process-global or interpreter state that would leak into (or be polluted by) other tests, depend on a clean interpreter startup, or may crash the interpreter outright. Today this has to be done ad hoc per test (spawning a child via
script_helper, hand-rolling the result reporting), which is verbose and inconsistent.I propose a decorator that runs a test in a dedicated subprocess and reports the result transparently, so the test reads like any other:
It would start in
test.supportand could later move tounittest.Proposed behaviour
@isolated()decorates a test method (only that method runs in a subprocess) or a wholeTestCasesubclass (the whole class runs in a single subprocess, sosetUpClass()/setUpModule()run once there).subTest()s — are reported for the corresponding test, and show the original subprocess traceback.setUpClass()/setUpModule()failure or skip in the subprocess is reported for the whole class.-u, memory limit-M, verbosity-v, failfast), sorequires_resource(),requires(),bigmemtest()and similar behave the same in both processes.running_isolatedflag is true while running in the subprocess, sosetUp()/tearDown()and the class- and module-level fixtures can choose what to run there.Linked PRs
Linked PRs