Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why django SimpleTestCase create test database

as explained in this question and in django docs, when using SimpleTestCase in unit testing, django should not create test database (which takes too long).

Inside one of my applications which is called "search, I have some unit test inherited from SimpleTestCase. this is tests.py inside search application:

class TokenizerTestCase(SimpleTestCase):
    def test_one(self):
        self.assertItemsEqual(1, 1)

When I call python manage.py test search.tests.TokenizerTestCase it takes too long to build default database. does anybody know why it is creating database for test?

like image 367
Ali Avatar asked Nov 30 '14 17:11

Ali


1 Answers

By default SimpleTestCase creates a test database. You can extend the class for your own functionality. If you do not want to create a database of your own in each and every setup setup your own test environment extending the classes.

Override the _pre_setup and _post_teardown methods. For more information read the source code for TransactionTestCase to see how it creates the test database structure.

Read the source code here

like image 171
Arpit Goyal Avatar answered Oct 20 '22 13:10

Arpit Goyal