mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-19 05:53:12 -04:00
✨ Add ResponseValidationError printable details, to show up in server error logs (#10078)
This commit is contained in:
committed by
GitHub
parent
dafaf6a34c
commit
5e8f7f13d7
@@ -47,3 +47,9 @@ class ResponseValidationError(ValidationException):
|
||||
def __init__(self, errors: Sequence[Any], *, body: Any = None) -> None:
|
||||
super().__init__(errors)
|
||||
self.body = body
|
||||
|
||||
def __str__(self) -> str:
|
||||
message = f"{len(self._errors)} validation errors:\n"
|
||||
for err in self._errors:
|
||||
message += f" {err}\n"
|
||||
return message
|
||||
|
||||
@@ -277,13 +277,15 @@ def test_response_model_no_annotation_return_exact_dict():
|
||||
|
||||
|
||||
def test_response_model_no_annotation_return_invalid_dict():
|
||||
with pytest.raises(ResponseValidationError):
|
||||
with pytest.raises(ResponseValidationError) as excinfo:
|
||||
client.get("/response_model-no_annotation-return_invalid_dict")
|
||||
assert "missing" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_response_model_no_annotation_return_invalid_model():
|
||||
with pytest.raises(ResponseValidationError):
|
||||
with pytest.raises(ResponseValidationError) as excinfo:
|
||||
client.get("/response_model-no_annotation-return_invalid_model")
|
||||
assert "missing" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_response_model_no_annotation_return_dict_with_extra_data():
|
||||
@@ -313,13 +315,15 @@ def test_no_response_model_annotation_return_exact_dict():
|
||||
|
||||
|
||||
def test_no_response_model_annotation_return_invalid_dict():
|
||||
with pytest.raises(ResponseValidationError):
|
||||
with pytest.raises(ResponseValidationError) as excinfo:
|
||||
client.get("/no_response_model-annotation-return_invalid_dict")
|
||||
assert "missing" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_no_response_model_annotation_return_invalid_model():
|
||||
with pytest.raises(ResponseValidationError):
|
||||
with pytest.raises(ResponseValidationError) as excinfo:
|
||||
client.get("/no_response_model-annotation-return_invalid_model")
|
||||
assert "missing" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_no_response_model_annotation_return_dict_with_extra_data():
|
||||
@@ -395,13 +399,15 @@ def test_response_model_model1_annotation_model2_return_exact_dict():
|
||||
|
||||
|
||||
def test_response_model_model1_annotation_model2_return_invalid_dict():
|
||||
with pytest.raises(ResponseValidationError):
|
||||
with pytest.raises(ResponseValidationError) as excinfo:
|
||||
client.get("/response_model_model1-annotation_model2-return_invalid_dict")
|
||||
assert "missing" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_response_model_model1_annotation_model2_return_invalid_model():
|
||||
with pytest.raises(ResponseValidationError):
|
||||
with pytest.raises(ResponseValidationError) as excinfo:
|
||||
client.get("/response_model_model1-annotation_model2-return_invalid_model")
|
||||
assert "missing" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_response_model_model1_annotation_model2_return_dict_with_extra_data():
|
||||
|
||||
Reference in New Issue
Block a user