[Python-checkins] cpython (3.3): Documentation corrections for unittest.mock
michael.foord
python-checkins at python.org
Mon Mar 18 23:05:01 CET 2013
http://hg.python.org/cpython/rev/9ac6a3871d76
changeset: 82737:9ac6a3871d76
branch: 3.3
parent: 82730:50af6682c6a7
user: Michael Foord <michael at voidspace.org.uk>
date: Mon Mar 18 15:04:03 2013 -0700
summary:
Documentation corrections for unittest.mock
files:
Doc/library/unittest.mock.rst | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst
--- a/Doc/library/unittest.mock.rst
+++ b/Doc/library/unittest.mock.rst
@@ -867,6 +867,25 @@
AttributeError: f
+Mock names and the name attribute
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Since "name" is an argument to the :class:`Mock` constructor, if you want your
+mock object to have a "name" attribute you can't just pass it in at creation
+time. There are two alternatives. One option is to use
+:meth:`~Mock.configure_mock`::
+
+ >>> mock = MagicMock()
+ >>> mock.configure_mock(name='my_name')
+ >>> mock.name
+ 'my_name'
+
+A simpler option is to simply set the "name" attribute after mock creation::
+
+ >>> mock = MagicMock()
+ >>> mock.name = "foo"
+
+
Attaching Mocks as Attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list