Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Assertion diff doesn't pretty-print the built-in frozen dict (Python 3.15)

オープン 初心者向け
#15,172 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@HakeemTheEmperor がすでに取り組んでいます。

2026年10月13日 から。

  • #15173 @HakeemTheEmperor による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
testing

調査の方向性

修正は 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

環境構築

はじめの一歩

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

pytest-dev/pytest のほかの issue

pytest-dev/pytest の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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