7

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?

Community
  • 1
  • 1
Ali
  • 6,808
  • 3
  • 37
  • 47
  • What does the startup look like? What text does Django display when you're running the tests? – Simeon Visser Nov 30 '14 at 18:46
  • @SimeonVisser at first line it writes: Creating test database for alias 'default'... then it prints some warnings about migrations. – Ali Dec 01 '14 at 09:56

1 Answers1

3

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

Arpit Goyal
  • 2,212
  • 11
  • 31