diff options
author | Michael Foord <michael@voidspace.org.uk> | 2011-10-09 18:12:06 +0100 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2011-10-09 18:12:06 +0100 |
commit | a52d8084f3958c2d23d133ca1a84e52a9211e3f2 (patch) | |
tree | 9337ef583436eaec75e60e3feb78a9da29116a2e /mock.py | |
parent | 31978ffa59e36b1fe11a19cefe2414843231e662 (diff) | |
download | mock-a52d8084f3958c2d23d133ca1a84e52a9211e3f2.tar.gz |
Implementation of attach_mock
Diffstat (limited to 'mock.py')
-rw-r--r-- | mock.py | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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 |