Django单元测试,每次我运行时都不会创建测试数据库 [英] Django unit test without creating test database everytime i run

查看:415
本文介绍了Django单元测试,每次我运行时都不会创建测试数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来像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:

您可以使用 SimpleTestCase

还有附加组件,如 django -test-utils (虽然我不知道那个特定的一个是否适用于现代的Django版本)。

There are also add-ons like django-test-utils (although I'm not sure if that specific one works with modern Django versions).

或者, ,您可以使用 SQLite的内存数据库或创建您的 RAM磁盘中的测试数据库(如tmpfs或ramfs) - 实际上这与使用其他技术是正交的。

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单元测试,每次我运行时都不会创建测试数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆