Add regression test and fixed dict insertion order in assertion diffs…#14086
Add regression test and fixed dict insertion order in assertion diffs…#14086anuranjansb wants to merge 7 commits intopytest-dev:mainfrom
Conversation
for more information, see https://pre-commit.ci
|
Thanks @anuranjansb, but this has the same issues as #14066. Please take a look at that PR's comments, specially the test that should be done. |
nicoddemus
left a comment
There was a problem hiding this comment.
Thanks @anuranjansb, but this has the same issues as #14066. Please take a look at that PR's comments, specially the test that should be done.
|
Thanks for pointing that out! I’ll review the comments on #14066 and adjust the regression test accordingly. I’ll update the test and follow up shortly. |
|
The issue has been fixed in PR #14050, so this is no longer needed. Thanks for the PR. |
What does this PR do?
This PR fixes an issue in pytest’s assertion comparison output where dictionary
insertion order is not preserved in verbose assertion diffs.
When comparing dictionaries with extra keys, the current output may inject the
extra key into the structured diff block, even though it belongs only to the
right-hand side. This leads to confusing output and breaks the expectation that
dict insertion order is respected.
This PR ensures that:
Right contains 1 more item)Why is this needed?
This is a regression highlighted in issue #14079.
Python dictionaries preserve insertion order, but pytest’s assertion diff output
did not consistently reflect this, especially for nested dictionaries combined
with wrapped output. This resulted in misleading diffs such as extra keys
appearing inside the left-hand structure.
What changes were made?
_compare_eq_dictlogic insrc/_pytest/assertion/util.pyto ensureextra keys are displayed only in the appropriate section.
testing/test_assertion.pythat fails under thecurrent behavior and passes with this fix.
How was this tested?