summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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