Path 1: 16 calls (1.0)

test_flaskgroup_debug..test def (2) shell_command def (1) routes_command def (1) test_app_cli_has_app_context..check def (1) test_with...

test_flaskgroup_debug..test def (2) shell_command def (1) routes_command def (1) test_app_cli_has_app_context..check def (1) test_with...

1def with_appcontext(f):
2    """Wraps a callback so that it's guaranteed to be executed with the
3    script's application context.
4
5    Custom commands (and their options) registered under ``app.cli`` or
6    ``blueprint.cli`` will always have an app context available, this
7    decorator is not required in that case.
8
9    .. versionchanged:: 2.2
10        The app context is active for subcommands as well as the
11        decorated callback. The app context is always available to
12        ``app.cli`` command and parameter callbacks.
13    """
14
15    @click.pass_context
16    def decorator(__ctx, *args, **kwargs):
17        if not current_app:
18            app = __ctx.ensure_object(ScriptInfo).load_app()
19            __ctx.with_resource(app.app_context())
20
21        return __ctx.invoke(f, *args, **kwargs)
22
23    return update_wrapper(decorator, f)