Skip to content

Conversation

@tirkarthi
Copy link
Member

@tirkarthi tirkarthi commented Jun 22, 2019

Since Python 3.6 the order of keyword arguments is preserved. Change mock.call repr and error messages to print the original order instead of sorting it.

https://bugs.python.org/issue37212

@tirkarthi tirkarthi changed the title bpo37212: Preserve keyword argument order in unittest.mock.call and error messages bpo-37212: Preserve keyword argument order in unittest.mock.call and error messages Jun 22, 2019
Copy link

@dhilst dhilst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Member

@ammaraskar ammaraskar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, preserving the call order is far more intuitive.

And for reference this is just a visual change useful for users introspecting test failures and such,

>>> m = Mock()
>>> m(b=1, a=2)
>>> m.assert_called_with(a=2, b=1)

works and will continue to work.

@zware zware merged commit 9d60706 into python:master Sep 9, 2019
@miss-islington
Copy link
Contributor

Thanks @tirkarthi for the PR, and @zware for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 9, 2019
…error messages (pythonGH-14310)

(cherry picked from commit 9d60706)

Co-authored-by: Xtreak <[email protected]>
@bedevere-bot
Copy link

GH-15755 is a backport of this pull request to the 3.8 branch.

@zware
Copy link
Member

zware commented Sep 9, 2019

Thanks for the patch, @tirkarthi, and for the reviews @dhilst and @ammaraskar! Due to the (admittedly very slim) chance that this could break things for someone who shouldn't be relying on repr orders anyway, I won't backport this further than 3.8.

miss-islington added a commit that referenced this pull request Sep 9, 2019
…error messages (GH-14310)

(cherry picked from commit 9d60706)

Co-authored-by: Xtreak <[email protected]>
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants