为我的烧瓶应用程序编写一些单元测试。当我在邮递员中尝试时,端点'/'有效并返回 200,但是 flask_testing 给出AssertionError: 404 != 200
我已经设置了一个基本配置。
class BaseTestCase(TestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///:memory:"
app.config['JWT_SECRET_KEY'] = environ['JWT_SECRET_KEY']
db = SQLAlchemy(app)
db.init_app(app)
return app
这是测试。
class FlaskTestCase(BaseTestCase):
def test_root(self):
response = self.client.get('/')
self.assertEquals(response.status_code, 200)
测试的输出
======================================================================
FAIL: test_root (test.server-test.FlaskTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/my_name/path/to/my_project/test/server-test.py", line 13, in test_root
self.assertEquals(response.status_code, 200)
AssertionError: 404 != 200
----------------------------------------------------------------------
Ran 1 test in 0.032s
FAILED (failures=1)