def app(request): """ Returns a session wide Flask app """ _app = create_app(TestingConfig) ctx = _app.app_context() ctx.push() yield _app ctx.pop()
def setup(self): self.app = create_app(config_name='testing') self.client = self.app.test_client self.driver_info = {'loc': 1.345000, 'lat': 1.345000, 'acc': 0.8} with self.app.app_context(): db.create_all()
def main(): app = my_app.create_app() dxhandler = dxpy.get_handler(dxpy.JOB_ID) dxhandler.set_properties({"httpsAppState": "running"}) app.run_server(host='0.0.0.0', port=443) return 1
from my_app import create_app, config app = create_app(config.Config) if __name__ == '__main__': app.run()
# -*- coding: utf-8 -*- import my_app app = my_app.create_app() if __name__ == '__main__': app.run_server(debug=True)
from my_app import create_app, config app = create_app(config.DevelopmentConfig) if __name__ == '__main__': app.run()
def setUp(self): """ Sets up the Flask application for testing """ app = create_app('config.TestingConfig') self.app = app.test_client()
from my_app import create_app from flask_script import Manager import os __author__ = "Preetam" app = create_app(os.getenv("FLASK_CONFIG") or "default") manager = Manager(app) if __name__ == "__main__": manager.run()
def create_app(self): app = create_app(config.TestingConfig) app.config['LIVESERVER_PORT'] = 8943 return app
from my_app import create_app app = create_app('development') app.run(debug=True)
def setUp(self): self.app = create_app(TestConfig) self.app_context = self.app.app_context() self.app_context.push() db.create_all()
# run.py import os from my_app import create_app config_name = os.getenv('FLASK_CONFIG') app = create_app(config_name) if __name__ == '__main__': app.run('0.0.0.0')
# coding: utf-8 import os from flask_script import Manager, Shell from my_app import create_app, db from my_app.models import Account, Token app = create_app(os.environ.get('FLASK_CONFIG') or 'default') def make_shell_context(): return dict(app=app, db=db, Account=Account, Token=Token) manager = Manager(app) manager.add_command('shell', Shell(make_context=make_shell_context)) # @manager.command # def test(): # """运行单元测试""" # import unittest # tests = unittest.TestLoader().discover('tests') # unittest.TextTestRunner(verbosity=2).run(tests) if __name__ == '__main__': manager.run()
def app(): test_app = create_app() yield test_app
def create_app(self): app = create_app(config.TestingConfig) return app
import os from flask_migrate import Migrate from my_app import create_app, db from my_app.models import User, Role app = create_app(os.getenv('FLASK_CONFIG') or 'default') migrate = Migrate(app, db) @app.shell_context_processor def make_shell_context(): return dict(db=db, User=User, Role=Role) @app.cli.command() def test(): import unittest tests = unittest.TestLoader().discover('tests') unittest.TextTestRunner(verbosity=2).run(tests)
from my_app import create_app app = create_app() if __name__ == '__main__': app.run(host='0.0.0.0', port=8000)
def create_app(self): return create_app('testing')