summaryrefslogtreecommitdiff
path: root/mock.py
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2011-10-09 18:12:06 +0100
committerMichael Foord <michael@voidspace.org.uk>2011-10-09 18:12:06 +0100
commita52d8084f3958c2d23d133ca1a84e52a9211e3f2 (patch)
tree9337ef583436eaec75e60e3feb78a9da29116a2e /mock.py
parent31978ffa59e36b1fe11a19cefe2414843231e662 (diff)
downloadmock-a52d8084f3958c2d23d133ca1a84e52a9211e3f2.tar.gz
Implementation of attach_mock
Diffstat (limited to 'mock.py')
-rw-r--r--mock.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/mock.py b/mock.py
index 8261d25..b9c6050 100644
--- a/mock.py
+++ b/mock.py
@@ -546,6 +546,19 @@ class NonCallableMock(Base):
)
+ def attach_mock(self, mock, attribute):
+ """
+ Attach a mock as an attribute of this one, replacing its name and
+ parent. Calls to the attached mock will be recorded in the
+ `method_calls` and `mock_calls` attributes of this one."""
+ mock._mock_parent = None
+ mock._mock_new_parent = None
+ mock._mock_name = ''
+ mock._mock_new_name = None
+
+ setattr(self, attribute, mock)
+
+
def mock_add_spec(self, spec, spec_set=False):
"""Add a spec to a mock. `spec` can either be an object or a
list of strings. Only attributes on the `spec` can be fetched as