summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMario Corchero <mariocj89@gmail.com>2018-10-19 21:57:37 (GMT)
committerVictor Stinner <vstinner@redhat.com>2018-10-19 21:57:37 (GMT)
commit96200eb2ffcda05de14099cf23f60d5091366e3e (patch)
tree7291dfed16ede85b754e6c7ca28df4cadb5145cc /Doc
parent5a30620e68ebb911eef4d583de3776d782148637 (diff)
downloadcpython-96200eb2ffcda05de14099cf23f60d5091366e3e.zip
cpython-96200eb2ffcda05de14099cf23f60d5091366e3e.tar.gz
cpython-96200eb2ffcda05de14099cf23f60d5091366e3e.tar.bz2
unittest.mock doc: Fix references to recursive seal of Mocks (GH-9028)
The docs in `library/unittest.mock` have been updated to remove confusing terms about submock and be explicit about the behavior expected.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/unittest.mock.rst9
1 files changed, 5 insertions, 4 deletions
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst
index edafca0..136804c 100644
--- a/Doc/library/unittest.mock.rst
+++ b/Doc/library/unittest.mock.rst
@@ -2410,17 +2410,18 @@ Sealing mocks
.. function:: seal(mock)
- Seal will disable the creation of mock children by preventing getting or setting
- of any new attribute on the sealed mock. The sealing process is performed recursively.
+ Seal will disable the automatic creation of mocks when accessing an attribute of
+ the mock being sealed or any of its attributes that are already mocks recursively.
- If a mock instance is assigned to an attribute instead of being dynamically created
+ If a mock instance with a name or a spec is assigned to an attribute
it won't be considered in the sealing chain. This allows one to prevent seal from
fixing part of the mock object. ::
>>> mock = Mock()
>>> mock.submock.attribute1 = 2
- >>> mock.not_submock = mock.Mock()
+ >>> 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.