我现在正在我的烧瓶项目中设置单元测试。我的测试文件如下:
import flask_testing
import unittest
from flask import Flask
from flask_testing import TestCase
class MyTest(TestCase):
def setUp(self):
pass # Executed before each test
def tearDown(self):
pass # Executed after each test
def create_app(self):
app = Flask(__name__)
# app.config['TESTING'] = True
return app
def test_greeting(self):
response = self.client.get('/')
print("should return 404 on landing page")
self.assertTemplateUsed('index.html')
self.assertEqual(response.status_code, 200)
if __name__ == '__main__':
unittest.main()
当我运行这些测试时,assertTemplateUsed
不返回模板并且response.status_code
是 404。我想这是因为 self 实际上不是我的应用程序出于某种原因?当我运行应用程序时,根地址肯定会返回 index.html。
我设置create_app
错了吗?任何帮助表示赞赏。