Skip to content
Myr

Merge pull request #3574 from jackwardell/adding-error-message-to-assert

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Adding error message to an assert

authored by David Lord · committed by GitHub · parents 2062d98, 846ee2c · Browse files · 2 files+11 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−1 removed

  • tests:+8 added−0 removed
  • other:+3 added−1 removed

2 files+11 added−1 removed

modified:src/flask/app.py+3 added-1 removed
1268 unmodified lines
1269 exc_class = default_exceptions[exc_class_or_code]1270 else:1271 exc_class = exc_class_or_code12721273 assert issubclass(exc_class, Exception)1273 assert issubclass(1274 exc_class, Exception1275 ), "Custom exceptions must be subclasses of Exception."12761277 if issubclass(exc_class, HTTPException):1278 return exc_class, exc_class.code1279 else:
1094 unmodified lines
modified:tests/test_user_error_handler.py+8 added
9 unmodified lines
10def test_error_handler_no_match(app, client):11 class CustomException(Exception):12 pass1314 class UnacceptableCustomException(BaseException):15 pass1617 @app.errorhandler(CustomException)18 def custom_exception_handler(e):19 assert isinstance(e, CustomException)20 return "custom"2122 with pytest.raises(23 AssertionError, match="Custom exceptions must be subclasses of Exception."24 ):25 app.register_error_handler(UnacceptableCustomException, None)2627 @app.errorhandler(500)28 def handle_500(e):29 assert isinstance(e, InternalServerError)30 original = getattr(e, "original_exception", None)
259 unmodified lines