Skip to content
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

bpo-31177: Skip deleted attributes while calling reset_mock #9302

Merged
merged 7 commits into from Dec 1, 2018

Conversation

@tirkarthi
Copy link
Member

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

Lib/unittest/test/testmock/testmock.py Show resolved Hide resolved
@@ -0,0 +1 @@
Skip deleted attributes while calling :meth:`mock.reset_mock`.

This comment has been minimized.

Copy link
@mariocj89

mariocj89 Oct 26, 2018

Contributor

I'd suggest rewording this to something around:

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

@tirkarthi tirkarthi force-pushed the tirkarthi:bpo31177 branch from a703d5c to c493115 Oct 26, 2018
@tirkarthi

This comment has been minimized.

Copy link
Member Author

tirkarthi commented Oct 26, 2018

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

Copy link
Contributor

mariocj89 left a 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.

tirkarthi added 2 commits Oct 27, 2018
@tirkarthi

This comment has been minimized.

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 left a comment

LGTM.

@tirkarthi

This comment has been minimized.

Copy link
Member Author

tirkarthi commented Nov 30, 2018

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

@vstinner

This comment has been minimized.

Copy link
Member

vstinner commented Nov 30, 2018

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

@vstinner vstinner merged commit edeca92 into python:master Dec 1, 2018
5 checks passed
5 checks passed
Azure Pipelines PR #20181201.2 succeeded
Details
bedevere/issue-number Issue number 31177 found
Details
bedevere/news News entry found in Misc/NEWS.d
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@miss-islington

This comment has been minimized.

Copy link

miss-islington commented Dec 1, 2018

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

This comment has been minimized.

Copy link

miss-islington commented Dec 1, 2018

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

@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Dec 1, 2018

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

@bedevere-bot

This comment has been minimized.

Copy link

bedevere-bot commented Dec 1, 2018

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

miss-islington added a commit to miss-islington/cpython that referenced this pull request Dec 1, 2018
…-9302)

(cherry picked from commit edeca92)

Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
miss-islington added a commit to miss-islington/cpython that referenced this pull request Dec 1, 2018
…-9302)

(cherry picked from commit edeca92)

Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
miss-islington added a commit that referenced this pull request Dec 1, 2018
(cherry picked from commit edeca92)

Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
miss-islington added a commit that referenced this pull request Dec 1, 2018
(cherry picked from commit edeca92)

Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
@vstinner

This comment has been minimized.

Copy link
Member

vstinner commented Dec 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.