Add option to not overwrite debug flag in cli

This is mainly intended for custom CLIs that may load a config file
which already sets the debug flag and does not make use of the `FLASK_*`
env vars at all.
This commit is contained in:
ThiefMaster 2018-05-08 18:05:55 +02:00
parent b34c7174e7
commit 50227f0954
3 changed files with 39 additions and 9 deletions

View file

@ -356,6 +356,28 @@ def test_flaskgroup(runner):
assert result.output == 'flaskgroup\n'
@pytest.mark.parametrize('set_debug_flag', (True, False))
def test_flaskgroup_debug(runner, set_debug_flag):
"""Test FlaskGroup debug flag behavior."""
def create_app(info):
app = Flask("flaskgroup")
app.debug = True
return app
@click.group(cls=FlaskGroup, create_app=create_app, set_debug_flag=set_debug_flag)
def cli(**params):
pass
@cli.command()
def test():
click.echo(str(current_app.debug))
result = runner.invoke(cli, ['test'])
assert result.exit_code == 0
assert result.output == '%s\n' % str(not set_debug_flag)
def test_print_exceptions(runner):
"""Print the stacktrace if the CLI."""