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
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:
class MyTest(unittest.TestCase):
@isolated()
def test_global_state(self):
...It would start in test.support and could later move to unittest.
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).- Failures, errors and skips — including those of individual
subTest()s — are reported for the corresponding test, and show the original subprocess traceback. - A
setUpClass()/setUpModule()failure or skip in the subprocess is reported for the whole class. - The subprocess inherits the parent's regrtest configuration (enabled resources
-u, memory limit-M, verbosity-v, failfast), sorequires_resource(),requires(),bigmemtest()and similar behave the same in both processes. - A
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
- gh-152548: Add the test.support.isolation.runInSubprocess() decorator #152551
- gh-152548: Convert test_audit to the test.support.isolation.runInSubprocess() decorator #152565
- gh-152548: Convert test_eintr to the test.support.isolation.runInSubprocess() decorator #152570
- gh-152548: Convert the test_signal wakeup tests to @runInSubprocess() #152639
- [3.15] gh-152548: Add a test.support.isolation.runInSubprocess() decorator (GH-152551) #154780
- [3.14] gh-152548: Add a test.support.isolation.runInSubprocess() decorator (GH-152551) #154783
- [3.13] gh-152548: Add a test.support.isolation.runInSubprocess() decorator (GH-152551) #154784
- gh-152548: Report a subprocess of runInSubprocess() dying after the test #155162
- gh-152548: Add options, env and timeout parameters to runInSubprocess() #155163
- [3.15] gh-152548: Report a subprocess of runInSubprocess() dying after the test (GH-155162) #155167
- [3.14] gh-152548: Report a subprocess of runInSubprocess() dying after the test (GH-155162) #155168
- [3.13] gh-152548: Report a subprocess of runInSubprocess() dying after the test (GH-155162) #155169
- [3.14] gh-152548: Add options, env and timeout parameters to runInSubprocess() (GH-155163) #155230
- [3.13] gh-152548: Add options, env and timeout parameters to runInSubprocess() (GH-155163) #155231
- [3.15] gh-152548: Add options, env and timeout parameters to runInSubprocess() (GH-155163) #155238
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-featureA feature request or enhancementA feature request or enhancement
Activity
pythongh-152548: Skip isolated() tests without subprocess support
pythongh-152548: Skip isolated() tests without subprocess support
pythongh-152548: Skip isolated() tests without subprocess support
pythongh-152548: Move per-test imports into the test methods in test_…
pythongh-152548: Address review of test.support.isolated()
pythongh-152548: Convert test_eintr to the @isolated() decorator
pythongh-152548: Convert test_audit to the @isolated() decorator
pythongh-152548: Fix the NEWS reference to the renamed isolated() dec…
pythongh-152548: Skip test_eintr where fcntl is unavailable
pythongh-152548: Rename isolated() to runInSubprocess() and address r…
pythongh-152548: Make runInSubprocess() robust for subclasses and bad…
pythongh-152548: Minimize what the runInSubprocess() child imports be…
gh-152548: Add a test.support.isolation.runInSubprocess() decorator (G…
7 remaining items
pythongh-152548: Skip the test_signal pipe write test without a subpr…
gh-152548: Report a subprocess of runInSubprocess() dying after the t…
pythongh-152548: Add options, env and timeout parameters to runInSubp…
[3.13] gh-152548: Report a subprocess of runInSubprocess() dying afte…
[3.14] gh-152548: Report a subprocess of runInSubprocess() dying afte…
[3.14] pythongh-152548: Report a subprocess of runInSubprocess() dyin…
gh-152548: Add options, env and timeout parameters to runInSubprocess…
[3.13] gh-152548: Add options, env and timeout parameters to runInSub…
[3.14] gh-152548: Add options, env and timeout parameters to runInSub…
pythongh-152548: Add a test.support.isolation.runInSubprocess() decor…
pythongh-152548: Report a subprocess of runInSubprocess() dying after…
pythongh-152548: Add options, env and timeout parameters to runInSubp…
[3.15] gh-152548: Report a subprocess of runInSubprocess() dying afte…
pythongh-152548: Add options, env and timeout parameters to runInSubp…
[3.15] gh-152548: Add options, env and timeout parameters to runInSub…