summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Foord <michael@voidspace.org.uk>2013-03-18 15:07:32 -0700
committerMichael Foord <michael@voidspace.org.uk>2013-03-18 15:07:32 -0700
commit77f44c2718bfca247353eda76577bbde1f0c8ba4 (patch)
treeb86245c2e1e82dcc6ae765d758969905bf6510f5
parent0dcbd0789acd58273bff38a3ae6e016ab5e37883 (diff)
downloadmock-77f44c2718bfca247353eda76577bbde1f0c8ba4.tar.gz
Doc update
-rw-r--r--docs/mock.txt19
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/mock.txt b/docs/mock.txt
index 58712b2..27a9c59 100644
--- a/docs/mock.txt
+++ b/docs/mock.txt
@@ -776,6 +776,25 @@ will raise an `AttributeError`.
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
=============================