diff options
author | Michael Foord <michael@voidspace.org.uk> | 2013-03-18 15:07:32 -0700 |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2013-03-18 15:07:32 -0700 |
commit | 0666b04a8b310c76eb13aa0a5932eff7d6f54112 (patch) | |
tree | b86245c2e1e82dcc6ae765d758969905bf6510f5 /docs | |
parent | 5b2729748e3cb72175bbbd85cd5fae0219b12f6d (diff) | |
download | mock-0666b04a8b310c76eb13aa0a5932eff7d6f54112.tar.gz |
Doc update
Diffstat (limited to 'docs')
-rw-r--r-- | docs/mock.txt | 19 |
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 ============================= |