Fix: assertrepr_compare respects dict insertion order#14050
Fix: assertrepr_compare respects dict insertion order#14050nicoddemus merged 4 commits intopytest-dev:mainfrom
Conversation
d415833 to
862ac24
Compare
862ac24 to
e1a94c1
Compare
|
Hey. Can someone review it? |
There was a problem hiding this comment.
Could you please also add an integration test like the one suggested in #14066 (comment)? Thanks!
testing/io/test_saferepr.py
Outdated
| ) | ||
|
|
||
|
|
||
| def test_saferepr_dict_preserves_insertion_order(): |
There was a problem hiding this comment.
Please add type annotations to the tests (-> None).
testing/io/test_saferepr.py
Outdated
|
|
||
|
|
||
| def test_saferepr_dict_preserves_insertion_order(): | ||
| d = {"b": 1, "a": 2} |
There was a problem hiding this comment.
Could we have more keys here just for safety?
| d = {"b": 1, "a": 2} | |
| d = { | |
| "b": 2, | |
| "a": 1, | |
| "d": 4, | |
| "e": 5, | |
| "c": 3, | |
| } |
changelog/14050.bugfix.rst
Outdated
| @@ -0,0 +1 @@ | |||
| Assertion comparison output now preserves dictionary insertion order instead of sorting keys. | |||
There was a problem hiding this comment.
| Assertion comparison output now preserves dictionary insertion order instead of sorting keys. | |
| Display dictionary differences in assertion failures using the original key insertion order instead of sorted order. |
testing/io/test_saferepr.py
Outdated
|
|
||
|
|
||
| def test_saferepr_dict_fillvalue_when_level_is_zero(): | ||
| from _pytest._io.saferepr import SafeRepr |
There was a problem hiding this comment.
Please move these imports from local to global.
nicoddemus
left a comment
There was a problem hiding this comment.
Thanks for the PR! Please take a look at my comments.
|
Sorry for being late @nicoddemus It's done. |
nicoddemus
left a comment
There was a problem hiding this comment.
Thanks! Appreciate the follow up.
Backport to 9.0.x: 💚 backport PR created✅ Backport PR branch: Backported as #14193 🤖 @patchback |
Closes #13503. Modified SafeRepr to override repr_dict and avoid sorting keys, ensuring that assertion failure messages preserve the user's insertion order for dictionaries.