bpo-39551: mock patch should match behavior of import from when module isn't present in sys.modules#18347
Closed
DinoV wants to merge 2 commits intopython:mainfrom
Closed
bpo-39551: mock patch should match behavior of import from when module isn't present in sys.modules#18347DinoV wants to merge 2 commits intopython:mainfrom
DinoV wants to merge 2 commits intopython:mainfrom
Conversation
cjw296
approved these changes
Jun 9, 2023
iritkatriel
requested changes
Jun 21, 2023
Member
iritkatriel
left a comment
There was a problem hiding this comment.
This has merge conflicts now.
|
When you're done making the requested changes, leave the comment: |
voidspace
reviewed
Jun 22, 2023
Contributor
voidspace
left a comment
There was a problem hiding this comment.
LGTM
One question - why manually use p1/p2 .start and .stop - is there a stopall in tearDown? Using patch as a context manager would seem more natural.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The fix for bpo-17636 added support for falling back to sys.modules when a module isn't directly present on the module. But mock doesn't have the same behavior - it'll try the import, and then try to get the value off the object. If it's not there it just errors out.
Instead it should also consult sys.modules to be consistent with import semantics.
This checks to see if the attribute is defined, and if it is returns it matching the existing behavior. If the attribute isn't defined it'll fallback to sys.modules.
https://bugs.python.org/issue39551