bpo-31177: Skip deleted attributes while calling reset_mock#9302
bpo-31177: Skip deleted attributes while calling reset_mock#9302vstinner merged 7 commits intopython:masterfrom
Conversation
There was a problem hiding this comment.
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.
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. |
|
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