Skip to content

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 into
python:mainfrom
DinoV:bp39551
Closed

bpo-39551: mock patch should match behavior of import from when module isn't present in sys.modules#18347
DinoV wants to merge 2 commits into
python:mainfrom
DinoV:bp39551

Conversation

@DinoV

@DinoV DinoV commented Feb 4, 2020

Copy link
Copy Markdown
Contributor

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

@iritkatriel iritkatriel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has merge conflicts now.

@bedevere-bot

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@voidspace voidspace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DinoV DinoV closed this May 31, 2024
@DinoV
DinoV deleted the bp39551 branch May 31, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants