mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
Error context and message (#183)
* POC of error context and message * Move type errors to the `errors.py` module; Change errors interface a bit * Rename `.as_dict()` to `.dict()` * Fix `PydanticErrorMixin` constructor * Rename `exceptions.py` to `error_wrappers.py` * Do not include nullable `ctx` * Fix tests * Added `int_validator`; Added `IntegerError` * Added `float_validator`; Added `FloatError` * Get rid of `__mro__` in prior of `exc.code` * Removed `min_number_size` and `max_number_size` from config (#174) * Added `NumberMinSizeError` and `NumberMaxSizeError` * Added `NoneIsNotAllowedError` * Added `EnumError` * Added `path_validator`; Added `PathError` * Added `DictError` * Added `ListError` * Added `TupleError` * Added `SetError` * Added `datetime` related errors * Added `bytes` and `str` related errors * Added `SequenceError` * Improved code coverage * Display error context in string representation of validation error * Redefine error message templates using config * Review fixes * Updated changelog
This commit is contained in:
committed by
Samuel Colvin
parent
0698384788
commit
4f4e22ef47
@@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
|
||||
from pydantic import PydanticTypeError
|
||||
|
||||
|
||||
def test_pydantic_error():
|
||||
class TestError(PydanticTypeError):
|
||||
code = 'test_code'
|
||||
msg_template = 'test message template "{test_ctx}"'
|
||||
|
||||
def __init__(self, *, test_ctx: int) -> None:
|
||||
super().__init__(test_ctx=test_ctx)
|
||||
|
||||
with pytest.raises(TestError) as exc_info:
|
||||
raise TestError(test_ctx='test_value')
|
||||
assert str(exc_info.value) == 'test message template "test_value"'
|
||||
Reference in New Issue
Block a user