MCPcopy
hub / github.com/pallets/flask / test_build_error_handler

Function test_build_error_handler

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

Source from the content-addressed store, hash-verified

1370
1371
1372def test_build_error_handler(app):
1373 # Test base case, a URL which results in a BuildError.
1374 with app.test_request_context():
1375 pytest.raises(BuildError, flask.url_for, "spam")
1376
1377 # Verify the error is re-raised if not the current exception.
1378 try:
1379 with app.test_request_context():
1380 flask.url_for("spam")
1381 except BuildError as err:
1382 error = err
1383 try:
1384 raise RuntimeError("Test case where BuildError is not current.")
1385 except RuntimeError:
1386 pytest.raises(BuildError, app.handle_url_build_error, error, "spam", {})
1387
1388 # Test a custom handler.
1389 def handler(error, endpoint, values):
1390 # Just a test.
1391 return "/test_handler/"
1392
1393 app.url_build_error_handlers.append(handler)
1394 with app.test_request_context():
1395 assert flask.url_for("spam") == "/test_handler/"
1396
1397
1398def 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