Testlerimin çalışması uzun sürüyor ve testler arasında bırakma ve tablolar oluşturma yerine testler arasında işlemler geri almayı deniyorum.Geri Alma Flask'taki testler arasındaki işlemler arasındaki işlemler
Bazı testlerde, birden çok işlem yaptığım sorunlardır.
DÜZENLEME: testler hızlı
İşte Test için kullanılan Taban sınıftır çalışacak şekilde nasıl test arasındaki işlemleri geri alma yoktur.
import unittest
from app import create_app
from app.core import db
from test_client import TestClient, TestResponse
class TestBase(unittest.TestCase):
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
self.app.response_class = TestResponse
self.app.test_client_class = TestClient
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
db.get_engine(self.app).dispose()
self.app_context.pop()
İşte işlemleri geri alma girişimi.
class TestBase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.app = create_app('testing')
cls.app_context = cls.app.app_context()
cls.app_context.push()
cls.app.response_class = TestResponse
cls.app.test_client_class = TestClient
db.create_all()
@classmethod
def tearDown(cls):
db.session.remove()
db.drop_all()
db.get_engine(cls.app).dispose()
def setUp(self):
self.app_content = self.app.app_context()
self.app_content.push()
db.session.begin(subtransactions=True)
def tearDown(self):
db.session.rollback()
db.session.close()
self.app_context.pop()
iken. Çalışan veritabanı komutlarını test etmeniz gerekmez. Ünite testleri iş mantığı içindir, bunun gibi sorunları önlemek için sahte bir veritabanı oluşturabilir ve veritabanınızı bozma riskiniz yoktur. – CodeLikeBeaker
Test için bellek içi db kullanıyor musunuz? Aksi takdirde, bu testler önemli ölçüde hızlandırabilir. – jsnjack
PostgreSQL'de bir test veritabanı kullanıyorum. – Siecje