diff options
| author | Michael Foord <michael@voidspace.org.uk> | 2013-03-18 22:04:33 (GMT) |
|---|---|---|
| committer | Michael Foord <michael@voidspace.org.uk> | 2013-03-18 22:04:33 (GMT) |
| commit | 35266f78b772bd7b13dc118206fa583264b1b2d3 (patch) | |
| tree | 1828cd4edd2b7328f90c7f734483bdf258800f86 | |
| parent | 1a48b9dd7dacbb298da2632a5196190de01587bb (diff) | |
| parent | f5752309813368f1a511d79c8b64a0888245932a (diff) | |
| download | cpython-35266f78b772bd7b13dc118206fa583264b1b2d3.zip cpython-35266f78b772bd7b13dc118206fa583264b1b2d3.tar.gz cpython-35266f78b772bd7b13dc118206fa583264b1b2d3.tar.bz2 | |
Merge
| -rw-r--r-- | 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 index 35e6c6c..c711565 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -887,6 +887,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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
