unittest.mock: Double period in AttributeError message for invalid assertion methods
オープン
まだ誰も着手していません。
stdlib
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
When accessing a non-existent assertion method on a [Mock] object( e.g., assert_called_twice_with), the raised [AttributeError] message contains a double period (..) before the "Did you mean" suggestion.
Example
import unittest.mock as mock
m = mock.Mock()
m.assert_called_twice_with(1, 2)
Output
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.12/unittest/mock.py", line 665, in __getattr__
raise AttributeError(
AttributeError: 'assert_called_twice_with' is not a valid assertion. Use a spec for the mock if 'assert_called_twice_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?
Problem
Note the double period ([attribute.. Did you mean] in the error message.
Expected Behavior
The error message should contain only a single period before the suggestion, e.g.:
Expected Output
AttributeError: 'assert_called_twice_with' is not a valid assertion. Use a spec for the mock if 'assert_called_twice_with' is meant to be an attribute. Did you mean: 'assert_called_once_with'?
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PR
Linked PRs
- gh-137717
- gh-138111
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
トレースバックに示されているエントリポイントである Mock.getattr の unittest/mock.py から始めます。無効なアサーションメソッドに関する既存の unittest.mock テストを確認し、候補が 1 つのピリオドの後に続くようにメッセージを調整します。関連するテストでは、修正された AttributeError の文言を確認できるようにします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- testing-qa
- issue の種類
- バグ
- 難易度
- 1/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100