@@ -197,17 +197,17 @@ def test_hello():
197
197
198
198
199
199
@pytest .mark .parametrize (
200
- "spec" ,
200
+ ( "expr" , "expected_passed" ) ,
201
201
[
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" ] ),
208
208
],
209
209
)
210
- def test_mark_option (spec , testdir ):
210
+ def test_mark_option (expr : str , expected_passed : str , testdir ) -> None :
211
211
testdir .makepyfile (
212
212
"""
213
213
import pytest
@@ -219,18 +219,17 @@ def test_two():
219
219
pass
220
220
"""
221
221
)
222
- opt , passed_result = spec
223
- rec = testdir .inline_run ("-m" , opt )
222
+ rec = testdir .inline_run ("-m" , expr )
224
223
passed , skipped , fail = rec .listoutcomes ()
225
224
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
228
226
229
227
230
228
@pytest .mark .parametrize (
231
- "spec" , [("interface" , ("test_interface" ,)), ("not interface" , ("test_nointer" ,))]
229
+ ("expr" , "expected_passed" ),
230
+ [("interface" , ["test_interface" ]), ("not interface" , ["test_nointer" ])],
232
231
)
233
- def test_mark_option_custom (spec , testdir ):
232
+ def test_mark_option_custom (expr : str , expected_passed : str , testdir ) -> None :
234
233
testdir .makeconftest (
235
234
"""
236
235
import pytest
@@ -248,26 +247,25 @@ def test_nointer():
248
247
pass
249
248
"""
250
249
)
251
- opt , passed_result = spec
252
- rec = testdir .inline_run ("-m" , opt )
250
+ rec = testdir .inline_run ("-m" , expr )
253
251
passed , skipped , fail = rec .listoutcomes ()
254
252
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
257
254
258
255
259
256
@pytest .mark .parametrize (
260
- "spec" ,
257
+ ( "expr" , "expected_passed" ) ,
261
258
[
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" ]),
268
266
],
269
267
)
270
- def test_keyword_option_custom (spec , testdir ):
268
+ def test_keyword_option_custom (expr : str , expected_passed : str , testdir ) -> None :
271
269
testdir .makepyfile (
272
270
"""
273
271
def test_interface():
@@ -282,12 +280,10 @@ def test_2():
282
280
pass
283
281
"""
284
282
)
285
- opt , passed_result = spec
286
- rec = testdir .inline_run ("-k" , opt )
283
+ rec = testdir .inline_run ("-k" , expr )
287
284
passed , skipped , fail = rec .listoutcomes ()
288
285
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
291
287
292
288
293
289
def test_keyword_option_considers_mark (testdir ):
@@ -298,14 +294,14 @@ def test_keyword_option_considers_mark(testdir):
298
294
299
295
300
296
@pytest .mark .parametrize (
301
- "spec" ,
297
+ ( "expr" , "expected_passed" ) ,
302
298
[
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]" ] ),
306
302
],
307
303
)
308
- def test_keyword_option_parametrize (spec , testdir ):
304
+ def test_keyword_option_parametrize (expr : str , expected_passed : str , testdir ) -> None :
309
305
testdir .makepyfile (
310
306
"""
311
307
import pytest
@@ -314,12 +310,10 @@ def test_func(arg):
314
310
pass
315
311
"""
316
312
)
317
- opt , passed_result = spec
318
- rec = testdir .inline_run ("-k" , opt )
313
+ rec = testdir .inline_run ("-k" , expr )
319
314
passed , skipped , fail = rec .listoutcomes ()
320
315
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
323
317
324
318
325
319
def test_parametrize_with_module (testdir ):
@@ -338,7 +332,7 @@ def test_func(arg):
338
332
339
333
340
334
@pytest .mark .parametrize (
341
- "spec" ,
335
+ ( "expr" , "expected_error" ) ,
342
336
[
343
337
(
344
338
"foo or" ,
@@ -360,17 +354,18 @@ def test_func(arg):
360
354
),
361
355
],
362
356
)
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 :
364
360
testdir .makepyfile (
365
361
"""
366
362
def test_func(arg):
367
363
pass
368
364
"""
369
365
)
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
374
369
375
370
376
371
def test_parametrized_collected_from_command_line (testdir ):
0 commit comments