RuntimeError: working outside of application context(运行时错误:在应用程序上下文之外工作)
问题描述
app.py
test.py
我正在将 app 导入 test.py 进行单元测试.在调用 'before_request' 函数到 test.py 时,它抛出运行时错误:在应用程序上下文之外工作调用 'input_info()'
I am importing app into test.py for unit testing.On calling 'before_request' function into test.py ,it is throwing RuntimeError: working outside of application context same is happening on calling 'input_info()'
推荐答案
Flask 有一个 应用程序上下文,似乎您需要执行以下操作:
Flask has an Application Context, and it seems like you'll need to do something like:
您也可以将 app.app_context()
调用推送到测试设置方法中.希望这会有所帮助.
You can probably also shove the app.app_context()
call into a test setup method as well. Hope this helps.
这篇关于运行时错误:在应用程序上下文之外工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!