Django test to use existing database

后端 未结 3 1433
再見小時候
再見小時候 2020-12-09 03:32

I\'m having a hard time customizing the test database setup behavior. I would like to achieve the following:

  • The test suites need to use an existing database
3条回答
  •  心在旅途
    2020-12-09 04:21

    Fast forward to 2016 and the ability to retain the database between tests has been built into django. It's available in the form of the --keep flag to manage.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.

    This pretty much fullfills all the criteria you have mentioned in your questions. In fact it even goes one step further. There is no need to import the dump before each and every run.

提交回复
热议问题