[Python-checkins] cpython (merge 3.3 -> default): Merge

michael.foord python-checkins at python.org
Mon Mar 18 23:05:03 CET 2013


http://hg.python.org/cpython/rev/72a8446fdf9a
changeset: 82738:72a8446fdf9a
parent: 82736:f972488c6b39
parent: 82737:9ac6a3871d76
user: Michael Foord <michael at voidspace.org.uk>
date: Mon Mar 18 15:04:33 2013 -0700
summary:
 Merge
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
@@ -887,6 +887,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

AltStyle によって変換されたページ (->オリジナル) /