gpt4 book ai didi

django - 如何避免在 django 中创建用于测试的测试数据库?

转载 作者:行者123 更新时间:2023-12-03 01:59:38 25 4
gpt4 key购买 nike

当我运行这些测试用例时,我为我的项目编写了一些测试用例,它每次都会为别名“默认”创建测试数据库,在给出消息后然后销毁数据库。我只关心消息,那么如何避免创建测试数据库,因为它需要很多时间。

username$ ./manage.py test
...............
Some message, I Want only this message
...............
Creating test database for alias 'default'...
----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
Destroying test database for alias 'default'...

最佳答案

python manage.py test -k

在 Django 1.8 中,您可以使用 -k 命令。

New in Django 1.8: You can prevent the test databases from being destroyed by adding the --keepdb flag to the test command. This will preserve the test database between runs. If the database does not exist, it will first be created. Any migrations will also be applied in order to keep it up to date.

您可以阅读以下内容了解更多详细信息: https://docs.djangoproject.com/en/1.8/topics/testing/overview/#the-test-database

关于django - 如何避免在 django 中创建用于测试的测试数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32644185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com