PyDocs

Nav

Development Tools

seal

unittest.mock

function · Added in 3.7 (source)
  • seal(mock)
Disable the automatic generation of child mocks.

Given an input Mock, seals it to ensure no further mocks will be generated
when accessing an attribute that was not already defined.

The operation recursively seals the mock passed in, meaning that
the mock itself, any mocks generated by accessing one of its attributes,
and all assigned mocks without a name or spec will be sealed.
1 Example
>>> mock = Mock()
>>> mock.submock.attribute1 = 2
>>> mock.not_submock = mock.Mock(name="sample_name")
>>> seal(mock)
>>> mock.new_attribute  # This will raise AttributeError.
>>> mock.submock.attribute2  # This will raise AttributeError.
>>> mock.not_submock.attribute2  # This won't raise.
from the Python docs
See Also
No see-alsos for unittest.mock/seal
0 Notes
No notes for seal