diff options
Diffstat (limited to 'Doc/library/unittest.mock.rst')
| -rw-r--r-- | Doc/library/unittest.mock.rst | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 9e8bf11..6fdfdc4 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -2365,3 +2365,23 @@ alternative object as the *autospec* argument: a mocked class to create a mock instance *does not* create a real instance. It is only attribute lookups - along with calls to :func:`dir` - that are done. +Sealing mocks +~~~~~~~~~~~~~ + +.. function:: seal(mock) + + Seal will disable the creation of mock children by preventing to get or set + any new attribute on the sealed mock. The sealing process is performed recursively. + + If a mock instance is assigned to an attribute instead of being dynamically created + it wont be considered in the sealing chain. This allows to prevent seal from fixing + part of the mock object. + + >>> mock = Mock() + >>> mock.submock.attribute1 = 2 + >>> mock.not_submock = mock.Mock() + >>> seal(mock) + >>> mock.submock.attribute2 # This will raise AttributeError. + >>> mock.not_submock.attribute2 # This won't raise. + + .. versionadded:: 3.7 |
