Assertion diff doesn't pretty-print the built-in frozen dict (Python 3.15)
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
修正は src/_pytest/_io/pprint.py に入れるべきです。PrettyPrinter._dispatch と既存の _pprint_ordered_dict ハンドラを読み、frozendict 型が存在する場合にのみ登録される frozendict ハンドラを追加してください。これにより、古い Python バージョンには影響しません。issue にある frozendict 2 要素のリストを使い、pytest -vv の下で再現してください。Full diff で各 frozendict のキーが別々の行に置かれ、変更された age の値がマークされ、新しいハンドラをカバーするテストが通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
Python 3.15 added frozendict as a built-in type (PEP 814). When an assertion
comparing frozendicts fails with -vv, the "Full diff" prints each frozendict on
a single line. A dict with the same contents gets one key per line, which makes
the changed value easy to spot. With frozendict the change is buried mid-line.
def test_frozendict():
left = [frozendict(name='alice', age=30, city='Lagos'), frozendict(name='bob', age=25, city='Abuja')]
right = [frozendict(name='alice', age=30, city='Lagos'), frozendict(name='bob', age=26, city='Abuja')]
assert left == right
Output with pytest -vv:
Full diff:
[
frozendict({'name': 'alice', 'age': 30, 'city': 'Lagos'}),
- frozendict({'name': 'bob', 'age': 26, 'city': 'Abuja'}),
? ^
+ frozendict({'name': 'bob', 'age': 25, 'city': 'Abuja'}),
? ^
]
The same test using dict:
Full diff:
[
{
'name': 'alice',
'age': 30,
'city': 'Lagos',
},
{
'name': 'bob',
- 'age': 26,
? ^
+ 'age': 25,
? ^
'city': 'Abuja',
},
]
I think the cause is in src/_pytest/_io/pprint.py. PrettyPrinter._dispatch
has handlers for dict, OrderedDict, defaultdict, MappingProxyType and
others, but not frozendict, so it falls back to a one-line repr(). The
standard library's pprint in 3.15 already supports frozendict.
A possible fix is a _pprint_frozendict handler similar to _pprint_ordered_dict,
registered only when frozendict exists, so older Python versions aren't affected.
Versions
pytest 9.1.1, Python 3.15.0, Windows 11. Also seen on pytest main with Python 3.15 on Linux.
pip list
Package Version
--------- -------
colorama 0.4.6
iniconfig 2.3.1
packaging 26.3
pip 26.2.1
pluggy 1.6.0
Pygments 2.21.0
pytest 9.1.1
I'm happy to open a PR for this.
- 主要言語
- Python
- スター
- 14.6k
- フォーク
- 3.5k
- 平均マージ
- 3日 18時間
- マージ済み PR(30日)
- 27
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pytest-dev/pytest のほかの issue
-
Docs build fails with Pluggy 1.7.0 on an unresolved private DistFacade reference対応中かも @Lothnic が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
pytest-dev/pytest#15190 ·
メンテナーはふだん 1 日以内に返信
-
`faulthandler_timeout` stops covering a test once setup, call or a subtest fails (`pytest_exception_interact` cancels the timer)対応中かも @XXXXXQ-0206 が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pytest-dev/pytest#15180 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
monkeypatch.setattr fails to undo on objects with a custom __setattr__ (regression from #14969)対応中かも @hardikkaurani が 22 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pytest-dev/pytest#15099 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
Allow dotted test filenames (`*.test.py`) via one-line change to `compute_module_name`再び着手できるかも @siddy-stack が 59 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
pytest-dev/pytest#14514 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
Expose CaptureManager as public API再び着手できるかも @harsh21234i が 197 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンtype: enhancement type: feature-branch
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
pytest-dev/pytest#14186 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
pytest-dev/pytest の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
UKGovernmentBEIS/control-arena#917 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
debpalash/VoiceStudio#2937 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
aws-samples/sample-per-model-bedrock#261 ·
メンテナーはふだん 1 日以内に返信