Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 1a48b9d + f575230 commit 35266f7Copy full SHA for 35266f7
1 file changed
Doc/library/unittest.mock.rst
@@ -887,6 +887,25 @@ will raise an `AttributeError`.
887
AttributeError: f
888
889
890
+Mock names and the name attribute
891
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
892
+
893
+Since "name" is an argument to the :class:`Mock` constructor, if you want your
894
+mock object to have a "name" attribute you can't just pass it in at creation
895
+time. There are two alternatives. One option is to use
896
+:meth:`~Mock.configure_mock`::
897
898
+ >>> mock = MagicMock()
899
+ >>> mock.configure_mock(name='my_name')
900
+ >>> mock.name
901
+ 'my_name'
902
903
+A simpler option is to simply set the "name" attribute after mock creation::
904
905
906
+ >>> mock.name = "foo"
907
908
909
Attaching Mocks as Attributes
910
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
911
0 commit comments