-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-31177: Skip deleted attributes while calling reset_mock #9302
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
Conversation
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.
I'd suggest rewording this to something around:
"Fix bug that prevented using reset_mock on mock instances with deleted attributes"
|
Thanks @mariocj89 for the review. I have made the suggested changes. |
mariocj89
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.
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.
|
@vstinner I have added the below comment to the test. Feel free to suggest rewording if needed. |
vstinner
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.
LGTM.
|
Please see #10807 that proposes deleted attributes to be retained that is different from my PR's behavior. |
|
Oops, I had a draft comment that I forgot to send! |
|
Thanks @tirkarthi for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6. |
|
Thanks @tirkarthi for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7. |
|
GH-10842 is a backport of this pull request to the 3.6 branch. |
|
GH-10843 is a backport of this pull request to the 3.7 branch. |
…-9302) (cherry picked from commit edeca92) Co-authored-by: Xtreak <[email protected]>
…-9302) (cherry picked from commit edeca92) Co-authored-by: Xtreak <[email protected]>
(cherry picked from commit edeca92) Co-authored-by: Xtreak <[email protected]>
(cherry picked from commit edeca92) Co-authored-by: Xtreak <[email protected]>
|
Thanks for the fix!
|
Skip the deleted attributes while calling
reset_mockso that it doesn't cause anAttributeError.Thanks
https://bugs.python.org/issue31177