title: Django Unit Testing taking a very long time to create test database
body: <p>For some time now, my unit testing has been taking a longer than expected time. I have tried to debug it a couple of times without much success, as the delays are before my tests even begin to run. This has affected my ability to do anything remotely close to test driven development (maybe my expectations are too high), so I want to see if I can fix this once and for all.</p>
  
  <p>When a run a test, there is a 70 to 80sec delay between the start and the actual beginning of the test. For example, if I run a test for a small module (using <code>time python manage.py test myapp</code>), I get</p>
  
  <pre><code>&lt;... bunch of unimportant print messages I print from my settings&gt;
  
  Creating test database for alias 'default'...
  ......
  ----------------------------------------------------------------
  Ran 6 tests in 2.161s
  
  OK
  Destroying test database for alias 'default'...
  
  real    1m21.612s
  user    1m17.170s
  sys     0m1.400s
  </code></pre>
  
  <p>About 1m18 of the 1m:21 are between the </p>
  
  <pre><code>Creating test database for alias 'default'...
  </code></pre>
  
  <p>and the </p>
  
  <pre><code>.......
  </code></pre>
  
  <p>line. In other words, the test takes under 3sec, but the database initialization seems to be taking 1:18min</p>
  
  <p>I have about 30 apps, most with 1 to 3 database models so this should give an idea of the project size. I use SQLite for unit testing, and have implemented some of the suggested improvements. I cannot post my whole setting file, but happy to add any information that is required.</p>
  
  <p>I do use a runner</p>
  
  <pre><code>from django.test.runner import DiscoverRunner
  from django.conf import settings
  
  class ExcludeAppsTestSuiteRunner(DiscoverRunner):
      """Override the default django 'test' command, exclude from testing
      apps which we know will fail."""
  
      def run_tests(self, test_labels, extra_tests=None, **kwargs):
          if not test_labels:
              # No appnames specified on the command line, so we run all
              # tests, but remove those which we know are troublesome.
              test_labels = (
                  'app1',
                  'app2',
                  ....
                  )
              print ('Testing: ' + str(test_labels))
  
          return super(ExcludeAppsTestSuiteRunner, self).run_tests(
                  test_labels, extra_tests, **kwargs)
  </code></pre>
  
  <p>and in my settings:</p>
  
  <pre><code>TEST_RUNNER = 'config.test_runner.ExcludeAppsTestSuiteRunner'
  </code></pre>
  
  <p>I have also tried using <code>django-nose</code> with <code>django-nose-exclude</code></p>
  
  <p>I have read a lot about how to speed up the test themselves, but have not found any leads on how to optimize or avoid the database initialization. I have seen the suggestions on trying not to test with the database but I cannot or don't know how to avoid that completely.</p>
  
  <p>Please let me know if</p>
  
  <ol>
  <li>This is normal and expected</li>
  <li>Not expected (and hopefully a fix or lead on what to do)</li>
  </ol>
  
  <p>Again, I don't need help on how to speed up the test themselves, but the initialization (or overhead). I want the example above to take 10sec instead of 80sec.</p>
  
  <p>Many thanks</p>
  
  <p>I run the test (for single app) with <code>--verbose 3</code> and discovered this is all related to migrations:</p>
  
  <pre><code>  Rendering model states... DONE (40.500s)
    Applying authentication.0001_initial... OK (0.005s)
    Applying account.0001_initial... OK (0.022s)
    Applying account.0002_email_max_length... OK (0.016s)
    Applying contenttypes.0001_initial... OK (0.024s)
    Applying contenttypes.0002_remove_content_type_name... OK (0.048s)
    Applying s3video.0001_initial... OK (0.021s)
    Applying s3picture.0001_initial... OK (0.052s)
    ... Many more like this
  </code></pre>
  
  <p>I squashed all my migrations but still slow.</p>