views:

238

answers:

2

In unit tests i need to load few fixtures this i have done as below

   class TestQuestionBankViews(TestCase):

        #load this fixtures
        fixtures = ['qbank',]

        def setUp(self):                           
            login = self.client.login(email="[email protected]",password="welcome")        


        def test_starting_an_exam_view(self):               
            candidate = Candidate.objects.get(email="[email protected]")
            .......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 flush the database after every test

How can i prevent that as it is taking lots of time?

Can't i load in setUP and flush them out while exit but not between every test.

Hope the problem is clear

+1  A: 

I've ran into the same problem. In general, there isn't a really good way to do that using django's test runner. You might be interested in this thread

With that being said, if all the testcases use the same fixture, and they don't modify the data in any way, then using initial_data would work.

jls
Rama Vadakattu
i decided to use unittest.TestCase with intial_data . Any idea on how to get all the conveniences provided by django.test.TestCase?
Rama Vadakattu
+1  A: 

I had a similar problem once and ended up writing my own test runner. In my case initial_data was not the right place as initial_data would be loaded during syncdb, something I did not want. I overrode setup_ and teardown_test_environment methods to load my custom fixture before the test suite was run and to remove it once done.

Manoj Govindan