0
我的申请有效。只有doctests不起作用。如何用flask-sqlalchemy编写doctests?
在应用程序中,我使用一个模式
from models import db
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://..."
db.init_app(app)
...
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', threaded=True)
我有几个非常简单的文档测试的。从瓶+ SQLAlchemy的切换到烧瓶的SQLAlchemy之前,它的工作:
>>> import database
>>> files_insert(..., no_commit=True) # database stuff happens here
>>> database.session.rollback()
它可以移除插件测试(他们可能没有什么太大的意义无论如何),但我有一对夫妇的功能,这只是需要从数据库中选择元素。这应该肯定仍然有效。但我得到:
RuntimeError: application not registered on db instance and no applicationbound to current context
是否有配置我的应用程序,以便文档字符串总是得到应用上下文的方法吗?