python / python/cpython

unittest mocks don't get applied to children with forkserver multiprocessing start method

オープン
#135,583 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:
import multiprocessing
import unittest
from unittest import mock


class Hello(unittest.TestCase):
    def _test_world(x):
        print(x, World().test())

    def test_world(self):
        # OK: multiprocessing.set_start_method("fork")
        # NOK: multiprocessing.set_start_method("forkserver")

        with mock.patch.object(World, "test", return_value=42):
            with multiprocessing.Pool(5) as pool:
                pool.map(Hello._test_world, range(5))


class World:
    def test(self):
        return 1

With "fork":

test.py 0 42
1 42
2 42
3 42
4 42

With "forkserver":

test.py 0 1
1 1
2 1
4 1
3 1
CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-152881

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue の再現コードから始め、unittest.mock.patch.object、multiprocessing.Pool、forkserver start method に焦点を当てます。fork と forkserver の動作を比較し、その後、関連付けられた PR gh-152881 を確認します。fork でリグレッションを起こさずに、報告された mock の動作が forkserver で解決されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。