问题描述
看起来像manage.py test每次运行测试时都会创建测试数据库。有没有办法防止每次运行测试时创建测试数据库,但只是截断数据(flush)?
Seems like "manage.py test" creates test database everytime i run the test. Is there a way to prevent creating test database each time i run test but just truncate data (flush)?
我的表几乎约有40个表(即使是单个应用程序,
My tables are almost about 40 tables (even for single app, not the whole project), and makes me sick everytime i run test.
推荐答案
根据您的需要,您可以选择几个选项:
Depending on your needs you have a few choices:
-
您可以编写一个自定义测试运行器或调整默认值:
您可以使用
还有附加组件,如(虽然我不知道那个特定的一个是否适用于现代的Django版本)。
There are also add-ons like django-test-utils (although I'm not sure if that specific one works with modern Django versions).
或者, ,您可以使用或创建您的 - 实际上这与使用其他技术是正交的。
Alternatively, to speed everything up, you could use SQLite's in-memory database OR create your test database in RAM disk (like tmpfs or ramfs) - in fact this is orthogonal to using other techniques.
这篇关于Django单元测试,每次我运行时都不会创建测试数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!