【发布时间】:2018-12-21 05:24:38
【问题描述】:
我有一个 Flask 服务器,它通过以下方式设置了 server.py
server.py
app = Flask(__name__)
app.register_blueprint(mybp)
if __name__ == '__main__':
app.config.foo = "bar"
mybp.py
@mybp.route('/', methods=['POST'])
def root():
return app.config.foo
test.py
@pytest.fixture
def client():
server.app.config['TESTING'] = True
client = server.app.test_client()
client
yield client
def testbp(client):
client.post('/mybp')
当我运行测试时,我得到以下错误
E AttributeError: 'Config' object has no attribute 'foo'
因为运行测试的时候配置还没有初始化。
【问题讨论】: