繁体   English   中英

django sqlite为别名'default'创建测试数据库

[英]django sqlite Creating test database for alias 'default'

我读了Q&A为什么django创建测试数据库 ,但在一个问题上没有答案。

我有django 1.8.4版本。

我的settings.py

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

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

测试工作大约2-3秒,所有其他时间它在为别名'default'创建测试数据库时挂起...

我认为我的数据库应该在内存中快速创建。 我没有加载json转储。 我怎样才能让它更快? 好像我错过了什么......

更新

如果我使用--keepdb标志(在答案中注意到它保留了我的数据库结构,而不是数据),无论如何,它以相同的方式挂起,但使用现有的测试数据库为别名'default'... label(

创建测试数据库是一项非常繁重的任务。 我认为大部分时间消耗是正常的。 但您可以使用'keepdb'标志来保留数据库以进行下一次测试运行:

python manage.py test --keepdb

在流浪汉中进行测试?

重启对我有用。

vagrant halt
vagrant up

我认为在我的情况下,测试崩溃了PyCharm调试器,它劫持了shell测试。

您也可以尝试重启MySQL

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM