Add a decorator to run a test in an isolated subprocess
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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-152551
- gh-152565
- gh-152570
- gh-152639
- gh-154780
- gh-154783
- gh-154784
- gh-155162
- gh-155163
- gh-155167
- gh-155168
- gh-155169
- gh-155230
- gh-155231
- gh-155238
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
test.support エントリーポイントと、script_helper にある既存の subprocess 処理から始めます。提案されているデコレータの動作と併せて、リンクされた pull request を確認します。これには、メソッドおよび TestCase での使用、結果の報告、継承された regrtest 設定、running_isolated が含まれます。指定された失敗、スキップ、fixture、subTests、および subprocess のトレースバックが透過的に報告されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- testing
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100