@@ -89,7 +89,7 @@ of the test:
89
89
def test_unix_fs ():
90
90
with mock.patch(' os.remove' ):
91
91
UnixFS.rm(' file' )
92
- os.remote .assert_called_once_with(' file' )
92
+ os.remove .assert_called_once_with(' file' )
93
93
94
94
with mock.patch(' os.listdir' ):
95
95
assert UnixFS.ls(' dir' ) == expected
@@ -100,8 +100,7 @@ of the test:
100
100
# ...
101
101
102
102
103
- One can use ``patch `` as a decorator to improve the flow of the test, but now the
104
- test functions must receive the mock objects:
103
+ One can use ``patch `` as a decorator to improve the flow of the test:
105
104
106
105
.. code-block :: python
107
106
@@ -110,14 +109,19 @@ test functions must receive the mock objects:
110
109
@mock.patch (' shutil.copy' )
111
110
def test_unix_fs (mocked_copy , mocked_listdir , mocked_copy ):
112
111
UnixFS.rm(' file' )
113
- os.remote .assert_called_once_with(' file' )
112
+ os.remove .assert_called_once_with(' file' )
114
113
115
114
assert UnixFS.ls(' dir' ) == expected
116
115
# ...
117
116
118
117
UnixFS.cp(' src' , ' dst' )
119
118
# ...
120
119
121
- Even when you prefer to access the mocks using the original references. Besides
122
- don't mixing nicely with other fixtures (although it works), you can't
123
- easily undo the mocking if you follow this approach.
120
+ But this poses a few disadvantages:
121
+
122
+ - test functions must receive the mock objects as parameter, even if you don't plan to
123
+ access them directly; also, order depends on the order of the decorated ``patch ``
124
+ functions;
125
+ - receiving the mocks as parameters doesn't mix nicely with pytest's approach of
126
+ naming fixtures as parameters, or ``pytest.mark.parametrize ``;
127
+ - you can't easily undo the mocking during the test execution;
0 commit comments