MCPcopy Index your code
hub / github.com/python/cpython / attach_mock

Method attach_mock

Lib/unittest/mock.py:510–522  ·  view source on GitHub ↗

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.

(self, mock, attribute)

Source from the content-addressed store, hash-verified

508
509
510 def attach_mock(self, mock, attribute):
511 """
512 Attach a mock as an attribute of this one, replacing its name and
513 parent. Calls to the attached mock will be recorded in the
514 `method_calls` and `mock_calls` attributes of this one."""
515 inner_mock = _extract_mock(mock)
516
517 inner_mock._mock_parent = None
518 inner_mock._mock_new_parent = None
519 inner_mock._mock_name = ''
520 inner_mock._mock_new_name = None
521
522 setattr(self, attribute, mock)
523
524
525 def mock_add_spec(self, spec, spec_set=False):

Calls 1

_extract_mockFunction · 0.85