Skip to content

Commit 28fb9a9

Browse files
committed
Update test_list_fail_fast
1 parent db30a76 commit 28fb9a9

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

tests/validators/test_list.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -397,21 +397,49 @@ def f(v: int) -> int:
397397
)
398398

399399

400-
def test_list_fail_fast():
401-
s = core_schema.list_schema(core_schema.int_schema(), fail_fast=True)
400+
@pytest.mark.parametrize(
401+
'fail_fast,expected',
402+
[
403+
pytest.param(
404+
True,
405+
[
406+
{
407+
'type': 'int_parsing',
408+
'loc': (1,),
409+
'msg': 'Input should be a valid integer, unable to parse string as an integer',
410+
'input': 'not-num',
411+
}
412+
],
413+
id='fail_fast',
414+
),
415+
pytest.param(
416+
False,
417+
[
418+
{
419+
'type': 'int_parsing',
420+
'loc': (1,),
421+
'msg': 'Input should be a valid integer, unable to parse string as an integer',
422+
'input': 'not-num',
423+
},
424+
{
425+
'type': 'int_parsing',
426+
'loc': (2,),
427+
'msg': 'Input should be a valid integer, unable to parse string as an integer',
428+
'input': 'again',
429+
},
430+
],
431+
id='not_fail_fast',
432+
),
433+
],
434+
)
435+
def test_list_fail_fast(fail_fast, expected):
436+
s = core_schema.list_schema(core_schema.int_schema(), fail_fast=fail_fast)
402437
v = SchemaValidator(s)
403438

404439
with pytest.raises(ValidationError) as exc_info:
405440
v.validate_python([1, 'not-num', 'again'])
406441

407-
assert exc_info.value.errors(include_url=False) == [
408-
{
409-
'type': 'int_parsing',
410-
'loc': (1,),
411-
'msg': 'Input should be a valid integer, unable to parse string as an integer',
412-
'input': 'not-num',
413-
}
414-
]
442+
assert exc_info.value.errors(include_url=False) == expected
415443

416444

417445
class MySequence(collections.abc.Sequence):

0 commit comments

Comments
 (0)