每次运行时都无需创建测试数据库的Django单元测试 [英] Django unit test without creating test database every time I run

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

问题描述

每次我运行测试时,好像 manage.py测试都会创建测试数据库。

Seems like "manage.py test" creates test database every time 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 every time 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天全站免登陆