【问题标题】:django sqlite Creating test database for alias 'default'django sqlite 为别名'default'创建测试数据库
【发布时间】:2016-05-29 01:54:47
【问题描述】:

我阅读了Q&A why django create test database,但没有一个问题的答案。

我有 django 1.8.4 版本。

我的设置.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 秒,所有其他时间都挂在为别名“默认”创建测试数据库...

我认为我的数据库应该非常快地在内存中创建。我没有加载 json 转储。我怎样才能让它更快?看来我错过了什么……

更新

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

【问题讨论】:

    标签: python django sqlite unit-testing testng


    【解决方案1】:

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

    python manage.py test --keepdb
    

    【讨论】:

    • 如果我的测试数据不是持久的并且可以修改或取决于时间戳,它是否有效?
    • 每次测试后都会清空数据库。但是django会保留数据库结构。它也适用于迁移
    • @ioganegambaputifonguser 我的回答对您有帮助吗?如果是,请接受。
    • 不幸的是,不,我认为我的 mac os 系统有些问题,我不得不在其他系统中完成工作。也很可悲,现在与 postgres 相同的行为,一切正常,但 django 挂起任何数据库查询(我投票赞成你的答案,但不能接受它
    【解决方案2】:

    在 vagrant 中运行测试?

    重启对我有用。

    vagrant halt
    vagrant up
    

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

    你也可以试试restarting MySQL

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      • 2012-04-20
      • 2020-11-17
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      相关资源
      最近更新 更多