@@ -95,9 +95,9 @@ The error messages in this situation are not very helpful on their own:
95
95
96
96
>> > for error in errors:
97
97
... print (error.message)
98
- The instance is not valid under any of the given schemas
99
- The instance is not valid under any of the given schemas
100
- The instance is not valid under any of the given schemas
98
+ {} is not valid under any of the given schemas
99
+ 3 is not valid under any of the given schemas
100
+ ' foo ' is not valid under any of the given schemas
101
101
102
102
If we look at :attr: `ValidationError.path ` on each of the errors, we can find
103
103
out which elements in the instance correspond to each of the errors. In
@@ -129,14 +129,27 @@ the schema each of these errors come from. In the case of sub-errors from the
129
129
130
130
>> > for error in errors:
131
131
... for suberror in sorted (error.context, key = lambda e : e.schema_path):
132
- ... print (list (suberror.schema_path), suberror, sep = " ," )
132
+ ... print (list (suberror.schema_path), suberror.message , sep = " , " )
133
133
[0 , ' type' ], {} is not of type ' string'
134
134
[1 , ' type' ], {} is not of type ' integer'
135
135
[0 , ' type' ], 3 is not of type ' string'
136
136
[1 , ' minimum' ], 3.0 is less than the minimum of 5
137
137
[0 , ' maxLength' ], ' foo' is too long
138
138
[1 , ' type' ], ' foo' is not of type ' integer'
139
139
140
+ The string representation of an error combines some of these attributes for
141
+ easier debugging.
142
+
143
+ .. code-block :: python
144
+
145
+ >> > print (errors[1 ])
146
+ ValidationError: 3 is not valid under any of the given schemas
147
+ Failed validating ' anyOf' in schema[' items' ]:
148
+ {' anyOf' : [{' maxLength' : 2 , ' type' : ' string' },
149
+ {' minimum' : 5 , ' type' : ' integer' }]}
150
+ On instance[1 ]:
151
+ 3
152
+ < BLANKLINE >
140
153
141
154
ErrorTrees
142
155
----------
0 commit comments