summaryrefslogtreecommitdiff
path: root/mock.py
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2011-10-08 01:13:25 +0100
committerMichael Foord <michael@voidspace.org.uk>2011-10-08 01:13:25 +0100
commit31978ffa59e36b1fe11a19cefe2414843231e662 (patch)
treeb6445be8ea7e480f7e31847b2554231c10b5998b /mock.py
parentd400c6fcc4f6cd04357b49f708cd342633b0c5f2 (diff)
downloadmock-31978ffa59e36b1fe11a19cefe2414843231e662.tar.gz
Setting a mock as a return value of itself no longer modifies repr of the mock
Diffstat (limited to 'mock.py')
-rw-r--r--mock.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/mock.py b/mock.py
index ff61610..8261d25 100644
--- a/mock.py
+++ b/mock.py
@@ -471,6 +471,14 @@ def _check_and_set_parent(parent, value, name, new_name):
(value._mock_new_parent is not None)):
return False
+ _parent = parent
+ while _parent is not None:
+ # setting a mock (value) as a child or return value of itself
+ # should not modify the mock
+ if _parent is value:
+ return False
+ _parent = _parent._mock_new_parent
+
if new_name:
value._mock_new_parent = parent
value._mock_new_name = new_name