forked from orbit-oss/flask
Merge pull request #3574 from jackwardell/adding-error-message-to-assert
Adding error message to an assert
This commit is contained in:
commit
d091bb00c0
2 changed files with 11 additions and 1 deletions
|
|
@ -1270,7 +1270,9 @@ class Flask(_PackageBoundObject):
|
||||||
else:
|
else:
|
||||||
exc_class = exc_class_or_code
|
exc_class = exc_class_or_code
|
||||||
|
|
||||||
assert issubclass(exc_class, Exception)
|
assert issubclass(
|
||||||
|
exc_class, Exception
|
||||||
|
), "Custom exceptions must be subclasses of Exception."
|
||||||
|
|
||||||
if issubclass(exc_class, HTTPException):
|
if issubclass(exc_class, HTTPException):
|
||||||
return exc_class, exc_class.code
|
return exc_class, exc_class.code
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,19 @@ def test_error_handler_no_match(app, client):
|
||||||
class CustomException(Exception):
|
class CustomException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class UnacceptableCustomException(BaseException):
|
||||||
|
pass
|
||||||
|
|
||||||
@app.errorhandler(CustomException)
|
@app.errorhandler(CustomException)
|
||||||
def custom_exception_handler(e):
|
def custom_exception_handler(e):
|
||||||
assert isinstance(e, CustomException)
|
assert isinstance(e, CustomException)
|
||||||
return "custom"
|
return "custom"
|
||||||
|
|
||||||
|
with pytest.raises(
|
||||||
|
AssertionError, match="Custom exceptions must be subclasses of Exception."
|
||||||
|
):
|
||||||
|
app.register_error_handler(UnacceptableCustomException, None)
|
||||||
|
|
||||||
@app.errorhandler(500)
|
@app.errorhandler(500)
|
||||||
def handle_500(e):
|
def handle_500(e):
|
||||||
assert isinstance(e, InternalServerError)
|
assert isinstance(e, InternalServerError)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue