1
我對此感到莫名其妙。我在Flask應用程序中使用應用程序工廠,在測試配置下,我的路線始終返回404s。404運行FlaskClient測試方法時的響應
然而,當我用瓶腳本並加載從解釋一切正常的應用程序,響應回來爲200
導航與瀏覽器的URL工作正常
應用程序/ __init__.py
def create_app():
app = Flask(__name__)
return app
sever1.py
個from flask import Flask
from flask_script import Manager
from app import create_app
app = create_app()
app_context = app.app_context()
app_context.push()
manager = Manager(app)
@app.route('/')
def index():
return '<h1>Hello World!</h1>'
@app.route('/user/<name>')
def user(name):
return '<h1>Hello, %s!</h1>' % name
@manager.command
def test():
"""Run the unit tests"""
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
if __name__ == '__main__':
manager.run()
測試/
#imports committed
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
self.client = self.app.test_client()
def test_app_exists(self):
response = self.client.get('/', follow_redirects=True)
print(response) #404 :(
self.assertTrue("Hello World!" in response.get_data()) #this is just an example of how it fails