我使用 flask_testing 编写测试代码
以下是我的测试代码
from app import create_app, db
class SampleTest(TestCase):
def create_app(self):
self.db_fd, self.db_path = tempflie.mkstemp()
return create_app({'DATABASE': self.db_path})
def setUp(self):
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
os.close(self.db_fd)
os.unlink(self.db_path)
def test1(self):
response = self.get('/test1/')
def test2(self):
response = self.get('/test2/')
在调试测试代码的时候,发现所有的测试函数都调用了create_app,包括test1、test。
我怎样才能只调用一次 create_app 函数?