Assertion diff doesn't pretty-print the built-in frozen dict (Python 3.15)
Maintainer thường phản hồi trong vòng 1 ngày
@HakeemTheEmperor đang làm issue này rồi.
Từ ngày 13/10/2026.
- #15173 của @HakeemTheEmperor — đang mở
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bản sửa nên nằm trong src/_pytest/_io/pprint.py. Đọc PrettyPrinter._dispatch và handler _pprint_ordered_dict hiện có, sau đó thêm một handler cho frozendict chỉ được đăng ký khi kiểu frozendict tồn tại, để các phiên bản Python cũ không bị ảnh hưởng. Tái hiện lỗi bằng danh sách hai phần tử gồm các frozendict trong issue với pytest -vv. Hoàn thành khi Full diff đặt các khóa của mỗi frozendict trên dòng riêng và giá trị age đã thay đổi được đánh dấu, và khi một test bao phủ handler mới vượt qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 14.6k
- Fork
- 3.5k
- Merge trung bình
- 2 ngày 21 phút
- Pull request đã merge (30 ngày)
- 24
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pytest-dev/pytest
-
Docs build fails with Pluggy 1.7.0 on an unresolved private DistFacade referenceCó thể đã có người làm @Lothnic đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
pytest-dev/pytest#15190 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`faulthandler_timeout` stops covering a test once setup, call or a subtest fails (`pytest_exception_interact` cancels the timer)Có thể đã có người làm @XXXXXQ-0206 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pytest-dev/pytest#15180 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
monkeypatch.setattr fails to undo on objects with a custom __setattr__ (regression from #14969)Có thể đã có người làm @hardikkaurani đã nhận 22 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pytest-dev/pytest#15099 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Allow dotted test filenames (`*.test.py`) via one-line change to `compute_module_name`Có thể làm lại được @siddy-stack đã nhận 60 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
pytest-dev/pytest#14514 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Expose CaptureManager as public APICó thể làm lại được @harsh21234i đã nhận 198 ngày trước và không có pull request nào đang mở. Đang mởtype: enhancement type: feature-branch
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
pytest-dev/pytest#14186 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của pytest-dev/pytest
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
lidofinance/diffyscan#239 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs: the dev-setup table and AGENTS.md name the reviewed_by guard that CI's Changelog job runsĐang mởarea: tools documentation good first issue ready for a contributor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
eyalgolan/statecraft-israel#873 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
GET rooms API returns 500 due to nonexistent Room.is_active attributeCó thể đã có người làm @Mars-60 đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add cover art to song rowsĐang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 5 ngày
-
Harmony OPeNDAP SubSetter (HOSS) Geographic production rssmif16d 7 XYZ_PROV
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
nasa/harmony-autotester#341 ·