-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix: assertrepr_compare respects dict insertion order #14050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: assertrepr_compare respects dict insertion order #14050
Conversation
d415833 to
862ac24
Compare
862ac24 to
e1a94c1
Compare
|
Hey. Can someone review it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please also add an integration test like the one suggested in #14066 (comment)? Thanks!
| ) | ||
|
|
||
|
|
||
| def test_saferepr_dict_preserves_insertion_order(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add type annotations to the tests (-> None).
|
|
||
|
|
||
| def test_saferepr_dict_preserves_insertion_order(): | ||
| d = {"b": 1, "a": 2} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, | |
| } |
| @@ -0,0 +1 @@ | |||
| Assertion comparison output now preserves dictionary insertion order instead of sorting keys. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
|
|
||
|
|
||
| def test_saferepr_dict_fillvalue_when_level_is_zero(): | ||
| from _pytest._io.saferepr import SafeRepr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these imports from local to global.
nicoddemus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Please take a look at my comments.
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.