我很难自定义测试数据库设置行为。我想实现以下目标:
我很难让 testsuiterunner 绕过创建。
最佳答案
快进到 2016 年,在 django 中内置了在测试之间保留数据库的能力。它以 --keep flag 的形式提供。管理.py
New in Django 1.8. Preserves the test database between test runs. This has the advantage of skipping both the create and destroy actions which can greatly decrease the time to run tests, especially those in a large test suite. If the test database does not exist, it will be created on the first run and then preserved for each subsequent run. Any unapplied migrations will also be applied to the test database before running the test suite.
这几乎满足了您在问题中提到的所有标准。事实上,它甚至更进一步。无需在每次运行之前导入转储。
关于Django 测试使用现有数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6250353/