MCPcopy Create free account
hub / github.com/pallets/flask / test_build_error_handler

Function test_build_error_handler

tests/test_basic.py:1344–1367  ·  view source on GitHub ↗
(app)

Source from the content-addressed store, hash-verified

1342
1343
1344def test_build_error_handler(app):
1345 # Test base case, a URL which results in a BuildError.
1346 with app.test_request_context():
1347 pytest.raises(BuildError, flask.url_for, "spam")
1348
1349 # Verify the error is re-raised if not the current exception.
1350 try:
1351 with app.test_request_context():
1352 flask.url_for("spam")
1353 except BuildError as err:
1354 error = err
1355 try:
1356 raise RuntimeError("Test case where BuildError is not current.")
1357 except RuntimeError:
1358 pytest.raises(BuildError, app.handle_url_build_error, error, "spam", {})
1359
1360 # Test a custom handler.
1361 def handler(error, endpoint, values):
1362 # Just a test.
1363 return "/test_handler/"
1364
1365 app.url_build_error_handlers.append(handler)
1366 with app.test_request_context():
1367 assert flask.url_for("spam") == "/test_handler/"
1368
1369
1370def test_build_error_handler_reraise(app):

Callers

nothing calls this directly

Calls 2

test_request_contextMethod · 0.80
url_forMethod · 0.80

Tested by

no test coverage detected