In unit tests I need to load fixtures, as below:
class TestQuestionBankViews(TestCase):
# Load fixtures
fixtures = ['qbank']
def setUp(self):
login = self.client.login(email="mail@gmail.com",password="welcome")
def test_starting_an_exam_view(self):
candidate = Candidate.objects.get(email="mail@gmail.com")
.......etc
def test_review_view(self):
self.assertTrue(True)
.........
def test_review_view2(self):
self.assertTrue(True)
.........
Problem:
These fixtures are loading for every test, i.e. before test_review_view, test_review_view2, etc., as Django flushes the database after every test.
This behaviour is causing tests to take a long time to complete.
How can I prevent this redundant fixture loading?
Is there a way to load fixtures in setUp
and flush them when the test class is finished, instead of flushing between every test?