Skip to content

Conversation

@tirkarthi
Copy link
Member

@tirkarthi tirkarthi commented Sep 14, 2018

Skip the deleted attributes while calling reset_mock so that it doesn't cause an AttributeError .

Thanks

https://bugs.python.org/issue31177

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest rewording this to something around:

"Fix bug that prevented using reset_mock on mock instances with deleted attributes"

@tirkarthi
Copy link
Member Author

Thanks @mariocj89 for the review. I have made the suggested changes.

Copy link
Contributor

@mariocj89 mariocj89 left a comment

Choose a reason for hiding this comment

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

Great! Thanks a lot :)

@vstinner, this seems to fix a bug in unittest.mock. When attributes are deleted in a mock they are marked with a mock.sentinel to prevent automatically creating other mocks dynamically, this is done by adding the _deleted sentinel to the child mocks dictionary.
The issue is that _reset_mock iterates over the list of child mocks assuming they are all Mocks without checking for the sentinel _deleted.

@tirkarthi
Copy link
Member Author

tirkarthi commented Oct 27, 2018

@vstinner I have added the below comment to the test. Feel free to suggest rewording if needed.

[bpo-31177](https://bugs.python.org/issue31177): reset_mock should not raise AttributeError when attributes 
were deleted in a mock instance

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

@tirkarthi
Copy link
Member Author

Please see #10807 that proposes deleted attributes to be retained that is different from my PR's behavior.

@vstinner
Copy link
Member

Oops, I had a draft comment that I forgot to send!

@miss-islington
Copy link
Contributor

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

@miss-islington
Copy link
Contributor

Thanks @tirkarthi for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-10842 is a backport of this pull request to the 3.6 branch.

@bedevere-bot
Copy link

GH-10843 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 1, 2018
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 1, 2018
miss-islington added a commit that referenced this pull request Dec 1, 2018
miss-islington added a commit that referenced this pull request Dec 1, 2018
@vstinner
Copy link
Member

vstinner commented Dec 1, 2018 via email

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.

6 participants