-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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-36593: Fix isinstance check for Mock objects with spec executed under tracing #12790
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.
LGTM
Thanks @pablogsal for the review :) I think this shouldn't have failed and have created an issue for |
Thanks @tirkarthi for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7. |
…nder tracing (pythonGH-12790) In Python having a trace function in effect while mock is imported causes isinstance to be wrong for MagicMocks. This is due to the usage of super() in some class methods, as this sets the __class__ attribute. To avoid this, as a workaround, alias the usage of super . (cherry picked from commit 830b43d) Co-authored-by: Xtreak <tir.karthi@gmail.com>
GH-12821 is a backport of this pull request to the 3.7 branch. |
…nder tracing (GH-12790) In Python having a trace function in effect while mock is imported causes isinstance to be wrong for MagicMocks. This is due to the usage of super() in some class methods, as this sets the __class__ attribute. To avoid this, as a workaround, alias the usage of super . (cherry picked from commit 830b43d) Co-authored-by: Xtreak <tir.karthi@gmail.com>
This issue occurs only when the mock module import and code are executed under tracing. In order to test this I have tried patching
sys.modules
to removeunittest.mock
in order to trigger an import under tracing. Thoughunittest.mock
is deleted reference tounittest.mock.patch
is held by two tests (test_patch_dict_test_prefix and test_patch_test_prefix) that change theTEST_PREFIX
. Hence somehow there is a difference in theunittest.mock.patch
object referred under these tests and inside mock module causing reference to unchangedTEST_PREFIX
and hence test case failures. So I have kept a reference to old patch object and restored it in the end of this test to make sure everything is in sync.https://bugs.python.org/issue36593