mocker's use of __import__ causes double module initialization
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mocker |
Fix Released
|
Undecided
|
Gustavo Niemeyer |
Bug Description
Mocker uses the idiom object = __import_
The Python 2.6 documentation now recommends a different idiom for use in this situation:
"If you simply want to import a module (potentially within a package) by
name, you can get it from sys.modules:
>>> import sys
>>> name = 'foo.bar.baz'
>>> __import__(name)
<module 'foo' from ...>
>>> baz = sys.modules[name]
>>> baz
<module 'foo.bar.baz' from ...>
"
I'm attaching a patch (against mocker 0.10.1) which makes mocker use this approach.
Changed in mocker: | |
status: | Fix Committed → Fix Released |
Thanks for the patch David. I've applied the change in revision 58.
In comparison to your patch, I've just reused the module_path variable.
This will be in Mocker 0.15 in a moment.