Skip to content

Commit de556f8

Browse files
authored
testing: clean up parametrization in test_mark.py (#7184)
1 parent 32c00db commit de556f8

File tree

1 file changed

+40
-45
lines changed

1 file changed

+40
-45
lines changed

testing/test_mark.py

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,17 @@ def test_hello():
197197

198198

199199
@pytest.mark.parametrize(
200-
"spec",
200+
("expr", "expected_passed"),
201201
[
202-
("xyz", ("test_one",)),
203-
("((( xyz)) )", ("test_one",)),
204-
("not not xyz", ("test_one",)),
205-
("xyz and xyz2", ()),
206-
("xyz2", ("test_two",)),
207-
("xyz or xyz2", ("test_one", "test_two")),
202+
("xyz", ["test_one"]),
203+
("((( xyz)) )", ["test_one"]),
204+
("not not xyz", ["test_one"]),
205+
("xyz and xyz2", []),
206+
("xyz2", ["test_two"]),
207+
("xyz or xyz2", ["test_one", "test_two"]),
208208
],
209209
)
210-
def test_mark_option(spec, testdir):
210+
def test_mark_option(expr: str, expected_passed: str, testdir) -> None:
211211
testdir.makepyfile(
212212
"""
213213
import pytest
@@ -219,18 +219,17 @@ def test_two():
219219
pass
220220
"""
221221
)
222-
opt, passed_result = spec
223-
rec = testdir.inline_run("-m", opt)
222+
rec = testdir.inline_run("-m", expr)
224223
passed, skipped, fail = rec.listoutcomes()
225224
passed = [x.nodeid.split("::")[-1] for x in passed]
226-
assert len(passed) == len(passed_result)
227-
assert list(passed) == list(passed_result)
225+
assert passed == expected_passed
228226

229227

230228
@pytest.mark.parametrize(
231-
"spec", [("interface", ("test_interface",)), ("not interface", ("test_nointer",))]
229+
("expr", "expected_passed"),
230+
[("interface", ["test_interface"]), ("not interface", ["test_nointer"])],
232231
)
233-
def test_mark_option_custom(spec, testdir):
232+
def test_mark_option_custom(expr: str, expected_passed: str, testdir) -> None:
234233
testdir.makeconftest(
235234
"""
236235
import pytest
@@ -248,26 +247,25 @@ def test_nointer():
248247
pass
249248
"""
250249
)
251-
opt, passed_result = spec
252-
rec = testdir.inline_run("-m", opt)
250+
rec = testdir.inline_run("-m", expr)
253251
passed, skipped, fail = rec.listoutcomes()
254252
passed = [x.nodeid.split("::")[-1] for x in passed]
255-
assert len(passed) == len(passed_result)
256-
assert list(passed) == list(passed_result)
253+
assert passed == expected_passed
257254

258255

259256
@pytest.mark.parametrize(
260-
"spec",
257+
("expr", "expected_passed"),
261258
[
262-
("interface", ("test_interface",)),
263-
("not interface", ("test_nointer", "test_pass", "test_1", "test_2")),
264-
("pass", ("test_pass",)),
265-
("not pass", ("test_interface", "test_nointer", "test_1", "test_2")),
266-
("not not not (pass)", ("test_interface", "test_nointer", "test_1", "test_2")),
267-
("1 or 2", ("test_1", "test_2")),
259+
("interface", ["test_interface"]),
260+
("not interface", ["test_nointer", "test_pass", "test_1", "test_2"]),
261+
("pass", ["test_pass"]),
262+
("not pass", ["test_interface", "test_nointer", "test_1", "test_2"]),
263+
("not not not (pass)", ["test_interface", "test_nointer", "test_1", "test_2"]),
264+
("1 or 2", ["test_1", "test_2"]),
265+
("not (1 or 2)", ["test_interface", "test_nointer", "test_pass"]),
268266
],
269267
)
270-
def test_keyword_option_custom(spec, testdir):
268+
def test_keyword_option_custom(expr: str, expected_passed: str, testdir) -> None:
271269
testdir.makepyfile(
272270
"""
273271
def test_interface():
@@ -282,12 +280,10 @@ def test_2():
282280
pass
283281
"""
284282
)
285-
opt, passed_result = spec
286-
rec = testdir.inline_run("-k", opt)
283+
rec = testdir.inline_run("-k", expr)
287284
passed, skipped, fail = rec.listoutcomes()
288285
passed = [x.nodeid.split("::")[-1] for x in passed]
289-
assert len(passed) == len(passed_result)
290-
assert list(passed) == list(passed_result)
286+
assert passed == expected_passed
291287

292288

293289
def test_keyword_option_considers_mark(testdir):
@@ -298,14 +294,14 @@ def test_keyword_option_considers_mark(testdir):
298294

299295

300296
@pytest.mark.parametrize(
301-
"spec",
297+
("expr", "expected_passed"),
302298
[
303-
("None", ("test_func[None]",)),
304-
("[1.3]", ("test_func[1.3]",)),
305-
("2-3", ("test_func[2-3]",)),
299+
("None", ["test_func[None]"]),
300+
("[1.3]", ["test_func[1.3]"]),
301+
("2-3", ["test_func[2-3]"]),
306302
],
307303
)
308-
def test_keyword_option_parametrize(spec, testdir):
304+
def test_keyword_option_parametrize(expr: str, expected_passed: str, testdir) -> None:
309305
testdir.makepyfile(
310306
"""
311307
import pytest
@@ -314,12 +310,10 @@ def test_func(arg):
314310
pass
315311
"""
316312
)
317-
opt, passed_result = spec
318-
rec = testdir.inline_run("-k", opt)
313+
rec = testdir.inline_run("-k", expr)
319314
passed, skipped, fail = rec.listoutcomes()
320315
passed = [x.nodeid.split("::")[-1] for x in passed]
321-
assert len(passed) == len(passed_result)
322-
assert list(passed) == list(passed_result)
316+
assert passed == expected_passed
323317

324318

325319
def test_parametrize_with_module(testdir):
@@ -338,7 +332,7 @@ def test_func(arg):
338332

339333

340334
@pytest.mark.parametrize(
341-
"spec",
335+
("expr", "expected_error"),
342336
[
343337
(
344338
"foo or",
@@ -360,17 +354,18 @@ def test_func(arg):
360354
),
361355
],
362356
)
363-
def test_keyword_option_wrong_arguments(spec, testdir, capsys):
357+
def test_keyword_option_wrong_arguments(
358+
expr: str, expected_error: str, testdir, capsys
359+
) -> None:
364360
testdir.makepyfile(
365361
"""
366362
def test_func(arg):
367363
pass
368364
"""
369365
)
370-
opt, expected_result = spec
371-
testdir.inline_run("-k", opt)
372-
out = capsys.readouterr().err
373-
assert expected_result in out
366+
testdir.inline_run("-k", expr)
367+
err = capsys.readouterr().err
368+
assert expected_error in err
374369

375370

376371
def test_parametrized_collected_from_command_line(testdir):

0 commit comments

Comments
 (0)