4

I read Q&A why django create test database, but there is no answer on a question.

I have django 1.8.4 version.

My settings.py

if 'test' in sys.argv or 'test_coverage' in sys.argv:
    DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'

Run

time ./manage.py test 

Raven is not configured (logging is disabled). Please see the documentation for more information.
/Users/ioganegambaputi/work/foobd/foobd/core/forms.py:7: RemovedInDjango19Warning: The django.forms.util module has been renamed. Use django.forms.utils instead.
  from django.forms.util import ErrorList

/Users/ioganegambaputi/work/env/foobd/lib/python2.7/site-packages/templated_email/__init__.py:2: RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
  from django.utils.importlib import import_module

/Users/ioganegambaputi/work/foobd/foobd/core/utils.py:50: RemovedInDjango19Warning: 'get_cache' is deprecated in favor of 'caches'.
  self.cache = cache.get_cache(cache_alias or cache.DEFAULT_CACHE_ALIAS)

Creating test database for alias 'default'...

real    0m53.102s
user    0m47.976s
sys     0m1.544s

The test works about 2-3 seconds, all other time it hangs in Creating test database for alias 'default'...

I think my database should be created in the memory very fast. I have no json dumps loaded. How can I make it faster? It seems I missed something...

UPDATED

If I use --keepdb flag (as noticed in the answer it keeps my database structure, but not the data), anyway, it hangs the same way, but with the Using existing test database for alias 'default'... label (

Community
  • 1
  • 1
fedorshishi
  • 1,467
  • 1
  • 18
  • 34

2 Answers2

4

Creating the test database is a quite heavy task. I think it's normal that it consumes most of the time. But you can use the 'keepdb' flag to keep the database for the next test runs:

python manage.py test --keepdb
ilse2005
  • 11,189
  • 5
  • 51
  • 75
  • is it works if my test data is not persistent and can be modified or depends of the timestamp? – fedorshishi Feb 17 '16 at 11:46
  • 1
    The database will be emptied after each test. But django will keep the database structure. It will also work with migrations – ilse2005 Feb 17 '16 at 11:49
  • @ioganegambaputifonguser Did my answer help you? If so accept it, please. – ilse2005 Mar 12 '16 at 01:20
  • 1
    unfortunately, no, I think something with my mac os system, I had to do the work in the other system. Also very sad, that now same behavior with the postgres, all works perfect but django hangs with the any database query ( I vote up your answer, but can`t accept it – fedorshishi Mar 12 '16 at 08:10
0

Running tests in vagrant?

Restarting did the trick for me.

vagrant halt
vagrant up

I think in my case, a test crashed PyCharm debugger which hijacked shell testing.

You can also try restarting MySQL

Shanimal
  • 11,517
  • 7
  • 63
  • 76