我正在为我的烧瓶应用程序使用自定义的 manage.py 脚本,该脚本是使用工厂模式创建的。
该脚本需要能够运行服务器并运行我的测试。我使用外部工具来运行我的测试,所以我不需要创建应用程序来运行测试。如何仅在运行某些命令时创建应用程序?
我的脚本目前看起来像:
import subprocess
import sys
from flask import current_app
from flask.cli import FlaskGroup
import click
from quizApp import create_app
@click.pass_context
def get_app(ctx, _):
"""Create an app with the correct config.
"""
return create_app(ctx.find_root().params["config"])
@click.option("-c", "--config", default="development",
help="Name of config to use for the app")
@click.group(cls=FlaskGroup, create_app=get_app)
def cli(**_):
"""Define the top level group.
"""
pass
@cli.command("test")
def test():
"""Set the app config to testing and run pytest, passing along command
line args.
"""
# This looks stupid, but see
# https://github.com/pytest-dev/pytest/issues/1357
sys.exit(subprocess.call(['py.test',
'--cov=quizApp',
'--flake8',
'--pylint',
'./']))
if __name__ == '__main__':
cli()
我尝试创建第二组,但似乎一次只能“运行”一个组,所以我不确定如何解决这个问题。