def _app(config_class): app = create_app(config_class) app.test_request_context().push() if config_class is TestingConfig: # always starting with an empty DB db.drop_all() db.create_all() return app
def testing_client(): app = create_app(TestingConfig) # Flask provides a way to test your application # by exposing the Werkzeug test Client # and handling the context locals for you. testing_client = app.test_client() # Establish an application context before running the tests. ctx = app.app_context() ctx.push() @app.before_first_request def init_db(): # always start with an empty DB db.drop_all() db.create_all() insert_test_user() yield testing_client # this is where the testing happens! ctx.pop()
from project_name import create_app app = create_app()
def create_app(test_config=None): return project_name.create_app(test_config)
from project_name import create_app, db from flask_script import Manager from flask_migrate import Migrate, MigrateCommand # 迁移的执行者和迁移的命令 # 创建flask的应用对象 app = create_app("develop") # 创建管理者 manager = Manager(app) # 把Migrate创建出来的迁移者对象保存到app中 Migrate(app, db) # 添加命令 manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run()