summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Niemeyer <gustavo@niemeyer.net>2010-06-20 12:06:45 -0300
committerGustavo Niemeyer <gustavo@niemeyer.net>2010-06-20 12:06:45 -0300
commitd8e15110fc3077683a264448a4ddedb59685b372 (patch)
treee36e92293ef4479d37f9dba47073afcbb1453507
parenta7565b37e0c07b7914bdbc41ec632778841f5bfa (diff)
downloadmocker-d8e15110fc3077683a264448a4ddedb59685b372.tar.gz
Applied change suggested by David Glick to avoid reimporting modules (#529675).
-rw-r--r--NEWS5
-rw-r--r--mocker.py3
2 files changed, 6 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index a883ce9..cab9e48 100644
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,10 @@
tries to use __length_hint__ in some cases.
- __nonzero__ should necessarily return a boolean value, so transform Mock
- results into True.
+ results into True (#380024).
+
+- Applied change suggested by David Glick to avoid reimporting modules
+ (#529675).
- When setting the temporary __mocker_mock__ attribute, use Mocker.patch()
so that by the end of the mocking it's properly removed (by Thomas Herve).
diff --git a/mocker.py b/mocker.py
index b5064c2..6945e5b 100644
--- a/mocker.py
+++ b/mocker.py
@@ -599,13 +599,14 @@ class MockerBase(object):
while import_stack:
module_path = ".".join(import_stack)
try:
- object = __import__(module_path, {}, {}, [""])
+ __import__(module_path)
except ImportError:
attr_stack.insert(0, import_stack.pop())
if not import_stack:
raise
continue
else:
+ object = sys.modules[module_path]
for attr in attr_stack:
object = getattr(object, attr)
break