diff --git a/tests/_templates.py b/tests/_templates.py index 1b2c78b..ef1e173 100644 --- a/tests/_templates.py +++ b/tests/_templates.py @@ -3,6 +3,7 @@ way to render a plugin's template in a test.""" import pathlib from jinja2 import ChoiceLoader, FileSystemLoader +from quart import render_template import steward @@ -16,11 +17,14 @@ def template_files() -> list[pathlib.Path]: async def render_plugin_template(app, plugin: str, name: str, **ctx) -> str: - """Render plugins//templates/ through the app's own Jinja - environment (its globals, filters and request context), whether or not the - plugin is enabled in this app. Call inside app.test_request_context().""" - env = app.jinja_env.overlay(loader=ChoiceLoader( - [FileSystemLoader(str(REPO / "plugins" / plugin / "templates")), app.jinja_env.loader])) - await app.update_template_context(ctx) - template = env.get_template(name) - return await template.render_async(**ctx) if env.is_async else template.render(**ctx) + """Render plugins//templates/ with quart.render_template, + whether or not the plugin is enabled in this app: the plugin's template + folder goes ahead of the app's loader for the one render. Call inside + app.test_request_context().""" + loader = app.jinja_env.loader + app.jinja_env.loader = ChoiceLoader( + [FileSystemLoader(str(REPO / "plugins" / plugin / "templates")), loader]) + try: + return await render_template(name, **ctx) + finally: + app.jinja_env.loader = loader