Using WebTest
WebTest (http://webtest.readthedocs.io) has been around for a long time. It was written by Ian Bicking back in the days of the Paste project, and is based on the WebOb (http://docs.webob.org) project, which provides a Request
and Response
class similar (but not compatible) to Flask's.
WebTest wraps call to a WSGI application like FlaskTest
does, and lets you interact with it. WebTest is somewhat similar to FlaskTest, with a few extra helpers when dealing with JSON, and a neat feature to call non-WSGI applications.
To use it with Flask, you can install the flask-webtest
package (https://flask-webtest.readthedocs.io/), and you will get a similar integration level as Flask's native tool:
import unittest from flask_basic import app as tested_app from flask_webtest import TestApp class TestMyApp(unittest.TestCase): def test_help(self): # creating a client to interact with the app app = TestApp(tested_app) # calling...