File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,46 @@ fixture:
69
69
ret = [mocker.Mock(return_value = True ), mocker.Mock(return_value = True )]
70
70
mocker.patch(' mylib.func' , side_effect = ret)
71
71
72
+ *New in version 0.5 *
73
+
74
+ Spy
75
+ ---
76
+
77
+ *New in version 0.6 *
78
+
79
+ The spy acts exactly like the original method in all cases, except it allows use of `mock `
80
+ features with it, like retrieving call count.
81
+
82
+ .. code-block :: python
83
+
84
+ def test_spy (mocker ):
85
+ class Foo (object ):
86
+ def bar (self ):
87
+ return 42
88
+
89
+ foo = Foo()
90
+ mocker.spy(foo, ' bar' )
91
+ assert foo.bar() == 42
92
+ assert foo.bar.call_count == 1
93
+
94
+ Stub
95
+ ----
96
+
97
+ *New in version 0.6 *
98
+
99
+ The stub is a mock object that accepts any arguments and is useful to test callbacks, for instance.
100
+
101
+ .. code-block :: python
102
+
103
+ def test_stub (mocker ):
104
+ def foo (on_something ):
105
+ on_something(' foo' , ' bar' )
106
+
107
+ stub = mocker.stub()
108
+
109
+ foo(stub)
110
+ stub.assert_called_once_with(' foo' , ' bar' )
111
+
72
112
Note
73
113
----
74
114
You can’t perform that action at this time.
0 commit comments