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

Function test_template_loader_debugging

tests/test_templating.py:407–440  ·  view source on GitHub ↗
(test_apps, monkeypatch)

Source from the content-addressed store, hash-verified

405
406
407def test_template_loader_debugging(test_apps, monkeypatch):
408 from blueprintapp import app
409
410 called = []
411
412 class _TestHandler(logging.Handler):
413 def handle(self, record):
414 called.append(True)
415 text = str(record.msg)
416 assert "1: trying loader of application 'blueprintapp'" in text
417 assert (
418 "2: trying loader of blueprint 'admin' (blueprintapp.apps.admin)"
419 ) in text
420 assert (
421 "trying loader of blueprint 'frontend' (blueprintapp.apps.frontend)"
422 ) in text
423 assert "Error: the template could not be found" in text
424 assert (
425 "looked up from an endpoint that belongs to the blueprint 'frontend'"
426 ) in text
427 assert "See https://flask.palletsprojects.com/blueprints/#templates" in text
428
429 with app.test_client() as c:
430 monkeypatch.setitem(app.config, "EXPLAIN_TEMPLATE_LOADING", True)
431 monkeypatch.setattr(
432 logging.getLogger("blueprintapp"), "handlers", [_TestHandler()]
433 )
434
435 with pytest.raises(TemplateNotFound) as excinfo:
436 c.get("/missing")
437
438 assert "missing_template.html" in str(excinfo.value)
439
440 assert len(called) == 1
441
442
443def test_custom_jinja_env():

Callers

nothing calls this directly

Calls 3

_TestHandlerClass · 0.85
test_clientMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected