Skip to content

Commit 270e975

Browse files
committed
Removed parametrization in favor of explicit tests
IMO they are more readable this way
1 parent 08add92 commit 270e975

File tree

1 file changed

+18
-39
lines changed

1 file changed

+18
-39
lines changed

test_pytest_mock.py

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections import namedtuple
21
import os
32

43
import pytest
@@ -149,50 +148,45 @@ def foo(on_something):
149148
stub.assert_called_once_with('foo', 'bar')
150149

151150

152-
def test_mocker_spy(mocker_spy_cases):
153-
foo, expect_obj = mocker_spy_cases
154-
155-
assert foo.bar(arg=10) == 20
156-
if expect_obj:
157-
foo.bar.assert_called_once_with(foo, arg=10)
158-
else:
159-
foo.bar.assert_called_once_with(arg=10)
160-
161-
162-
def create_instance_method_spy(mocker):
151+
def test_instance_method_spy(mocker):
163152
class Foo(object):
164153

165154
def bar(self, arg):
166155
return arg * 2
167156

168157
foo = Foo()
169158
mocker.spy(foo, 'bar')
170-
return foo, False
159+
assert foo.bar(arg=10) == 20
160+
foo.bar.assert_called_once_with(arg=10)
171161

172162

173-
def create_instance_method_by_class_spy(mocker):
163+
def test_instance_method_by_class_spy(mocker):
174164
class Foo(object):
175165

176166
def bar(self, arg):
177167
return arg * 2
178168

179169
mocker.spy(Foo, 'bar')
180-
return Foo(), True
170+
foo = Foo()
171+
assert foo.bar(arg=10) == 20
172+
foo.bar.assert_called_once_with(foo, arg=10)
181173

182174

183-
def create_class_method_spy(mocker):
175+
def test_class_method_spy(mocker):
184176
class Foo(object):
185177

186178
@classmethod
187179
def bar(cls, arg):
188180
return arg * 2
189181

190182
mocker.spy(Foo, 'bar')
191-
return Foo, False
183+
assert Foo.bar(arg=10) == 20
184+
Foo.bar.assert_called_once_with(arg=10)
192185

193186

194-
def create_class_method_with_metaclass_spy(mocker):
195-
class MetaFoo(type): pass
187+
def test_class_method_with_metaclass_spy(mocker):
188+
class MetaFoo(type):
189+
pass
196190

197191
class Foo(object):
198192

@@ -203,33 +197,18 @@ def bar(cls, arg):
203197
return arg * 2
204198

205199
mocker.spy(Foo, 'bar')
200+
assert Foo.bar(arg=10) == 20
201+
Foo.bar.assert_called_once_with(arg=10)
206202
return Foo, False
207203

208204

209-
def create_static_method_spy(mocker):
205+
def test_static_method_spy(mocker):
210206
class Foo(object):
211207

212208
@staticmethod
213209
def bar(arg):
214210
return arg * 2
215211

216212
mocker.spy(Foo, 'bar')
217-
return Foo, False
218-
219-
220-
mock_spy_case = namedtuple('mock_spy_case', ['do', 'name'])
221-
222-
@pytest.fixture(
223-
params=[
224-
mock_spy_case(do=create_instance_method_spy, name='instance_method'),
225-
mock_spy_case(do=create_instance_method_by_class_spy, name='instance_method_by_class'),
226-
mock_spy_case(do=create_class_method_spy, name='classmethod'),
227-
mock_spy_case(do=create_class_method_with_metaclass_spy, name='classmethod_with_metaclass'),
228-
mock_spy_case(do=create_static_method_spy, name='staticmethod'),
229-
],
230-
ids=lambda i: i.name,
231-
)
232-
def mocker_spy_cases(mocker, request):
233-
case = request.param
234-
235-
return case.do(mocker)
213+
assert Foo.bar(arg=10) == 20
214+
Foo.bar.assert_called_once_with(arg=10)

0 commit comments

Comments
 (0)