python / python/cpython

Unitest.mock.MagicMock raises a StopIteration - not following PEP 479

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

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

stdlib
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

説明

It looks like Unitest.mock.MagicMock raises a StopIteration when repeated calls to the mock are made and an iterable is exhausted. After Python 3.7+, due to PEP 479, this raises a Runtime Error. This makes unit tests that worked in Python 3.6 fail, including any list comprehensions on MagicMock results. These can be easily caught with a try/except, but it's a bit clunky.

According to PEP 479 instead of StopIteration MagicMock should just return return when the iterable is exhausted. See here: https://peps.python.org/pep-0479/

Please let me know if I missed something on my end. Thanks for looking into this.

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

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

はじめの一歩

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

調査の方向性

unittest.mock.MagicMock から始め、使い果たされた iterable に対する繰り返しの呼び出しを、list comprehension での使用も含めて再現します。PEP 479 を、mock の iterable な side effect の挙動と併せて読みます。使い果たされた iterable の意図した挙動が確立され、回帰テストでカバーされれば完了です。

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

評価

技術スタック
python
領域
testing-qa
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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