def app(): #產生一個暫存檔並回傳file object和他的路徑, #測試用的sqlite會產生在暫存檔裡 #測試後關閉並移除 db_fd, db_path = tempfile.mkstemp() app = create_app({ 'TESTING': True, 'DATABASE': db_path, }) with app.app_context(): init_db() get_db().executescript(_data_sql) yield app os.close(db_fd) os.unlink(db_path)
from flaskBlog import create_app app = create_app() if __name__ == '__main__': website_url = 'mysite.pai:5000' app.config['SERVER_NAME'] = website_url app.run( debug=True)
def test_config(): assert not create_app().testing assert create_app({'TESTING': True}).testing