I'm new to Flask and am trying to understand how to initialise the app in tests so that the routes are hooked up. According to the Flask-Testing docs this is done with (for the LiveServerTestCase):
class MyTest(LiveServerTestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
# Default port is 5000
app.config['LIVESERVER_PORT'] = 8943
# Default timeout is 5 seconds
app.config['LIVESERVER_TIMEOUT'] = 10
return app
However, I have a separate module containing the views using @app.route
pattern to register them. My question is, how can I register these routes in the testcase so that the app is cleanly created and torn down? Currently I can only make this work by importing the app from the views module itself, which feels like the wrong way of doing things. What is the usual way of setting this up?
Aucun commentaire:
Enregistrer un commentaire