我有一些包含大量数据的表格(使用django-cities导入的geonames:https://github.com/coderholic/django-cities)我想在测试中保留(因为通过灯具加载它们会非常慢)...我怎么能保持测试期间那些表及其数据? 我想我必须编写一个自定义的TestRunner,但我不知道从哪里开始:P
答案 0 :(得分:1)
这是可能的,这是一种方式:
1)定义您自己的测试跑步者外观here,看看如何。
2)对于您的自定义测试运行器,请查看default test runner,您可以复制并通过代码,只需注释这一行:connection.creation.destroy_test_db(old_name, verbosity)
负责销毁测试数据库,我认为您应该尝试connection.creation.create_test_db(..)
行,除非像这样:
try:
# Create the database the first time.
connection.creation.create_test_db(verbosity, autoclobber=not interactive)
except ..: # Look at the error that this will raise when create a database that already exist
# Test database already created.
pass
3)将setting.py中的TEST_RUNNER绑定到测试运行器。
4)现在运行你的测试:./ manage.py test