@@ -553,27 +553,31 @@ def test_error_json_loc():
553
553
554
554
def test_raise_validation_error ():
555
555
with pytest .raises (ValidationError , match = '1 validation error for Foobar\n ' ) as exc_info :
556
- raise ValidationError ('Foobar' , [{'type' : 'greater_than' , 'loc' : ('a' , 2 ), 'input' : 4 , 'ctx' : {'gt' : 5 }}])
556
+ raise ValidationError .from_exception_data (
557
+ 'Foobar' , [{'type' : 'greater_than' , 'loc' : ('a' , 2 ), 'input' : 4 , 'ctx' : {'gt' : 5 }}]
558
+ )
557
559
558
560
# insert_assert(exc_info.value.errors(include_url=False))
559
561
assert exc_info .value .errors (include_url = False ) == [
560
562
{'type' : 'greater_than' , 'loc' : (2 , 'a' ), 'msg' : 'Input should be greater than 5' , 'input' : 4 , 'ctx' : {'gt' : 5 }}
561
563
]
562
564
with pytest .raises (TypeError , match = 'GreaterThan requires context: {gt: Number}' ):
563
- raise ValidationError ('Foobar' , [{'type' : 'greater_than' , 'loc' : ('a' , 2 ), 'input' : 4 }])
565
+ raise ValidationError . from_exception_data ('Foobar' , [{'type' : 'greater_than' , 'loc' : ('a' , 2 ), 'input' : 4 }])
564
566
565
567
566
568
def test_raise_validation_error_json ():
567
569
with pytest .raises (ValidationError ) as exc_info :
568
- raise ValidationError ('Foobar' , [{'type' : 'none_required' , 'loc' : [- 42 ], 'input' : 'x' }])
570
+ raise ValidationError . from_exception_data ('Foobar' , [{'type' : 'none_required' , 'loc' : [- 42 ], 'input' : 'x' }])
569
571
570
572
# insert_assert(exc_info.value.errors(include_url=False))
571
573
assert exc_info .value .errors (include_url = False ) == [
572
574
{'type' : 'none_required' , 'loc' : (- 42 ,), 'msg' : 'Input should be None' , 'input' : 'x' }
573
575
]
574
576
575
577
with pytest .raises (ValidationError ) as exc_info :
576
- raise ValidationError ('Foobar' , [{'type' : 'none_required' , 'loc' : (), 'input' : 'x' }], 'json' )
578
+ raise ValidationError .from_exception_data (
579
+ 'Foobar' , [{'type' : 'none_required' , 'loc' : (), 'input' : 'x' }], 'json'
580
+ )
577
581
578
582
# insert_assert(exc_info.value.errors(include_url=False))
579
583
assert exc_info .value .errors (include_url = False ) == [
@@ -586,7 +590,7 @@ def test_raise_validation_error_custom():
586
590
'my_error' , 'this is a custom error {missed} {foo} {bar}' , {'foo' : 'X' , 'bar' : 42 }
587
591
)
588
592
with pytest .raises (ValidationError ) as exc_info :
589
- raise ValidationError ('Foobar' , [{'type' : custom_error , 'input' : 'x' }])
593
+ raise ValidationError . from_exception_data ('Foobar' , [{'type' : custom_error , 'input' : 'x' }])
590
594
591
595
# insert_assert(exc_info.value.errors(include_url=False))
592
596
assert exc_info .value .errors (include_url = False ) == [
@@ -631,14 +635,3 @@ def test_loc_with_dots():
631
635
"[type=int_parsing, input_value='x', input_type=str]\n "
632
636
f' For further information visit https://errors.pydantic.dev/{ __version__ } /v/int_parsing'
633
637
)
634
-
635
-
636
- def subclass_validation_error ():
637
- class MyValidationError (ValidationError ):
638
- def __init__ (self , title : str , errors , error_mode = 'python' ):
639
- self .body = 123
640
- super ().__init__ (title , errors , error_mode )
641
-
642
- e = MyValidationError ('testing' , [])
643
- assert e .body == 123
644
- assert e .title == 'testing'
0 commit comments