added exception chain rendering in debug #675

This commit is contained in:
Alec Buckenheimer
2017-05-01 12:56:33 -04:00
parent 158a94d34c
commit 69511c2783
3 changed files with 75 additions and 13 deletions

View File

@@ -35,6 +35,15 @@ def handler_5(request):
raise CustomServerError('Custom server error')
@exception_handler_app.route('/6/<arg:int>')
def handler_6(request, arg):
try:
foo = 1 / arg
except Exception as e:
raise e from ValueError("{}".format(arg))
return text(foo)
@exception_handler_app.exception(NotFound, ServerError)
def handler_exception(request, exception):
return text("OK")
@@ -84,6 +93,26 @@ def test_inherited_exception_handler():
assert response.status == 200
def test_chained_exception_handler():
request, response = exception_handler_app.test_client.get(
'/6/0', debug=True)
assert response.status == 500
soup = BeautifulSoup(response.body, 'html.parser')
html = str(soup)
assert 'response = handler(request, *args, **kwargs)' in html
assert 'handler_6' in html
assert 'foo = 1 / arg' in html
assert 'ValueError' in html
assert 'The above exception was the direct cause' in html
summary_text = " ".join(soup.select('.summary')[0].text.split())
assert (
"ZeroDivisionError: division by zero "
"while handling path /6/0") == summary_text
def test_exception_handler_lookup():
class CustomError(Exception):
pass