你可以破解这个选项
--keepdb
输入源代码。
你需要编辑这个文件
django/db/backends/creation.py
这样地:
256c256,259
< self._create_test_db(verbosity, autoclobber)
---
> skip = True
>
> if not skip:
> self._create_test_db(verbosity, autoclobber)
264,281c267,285
< # Report syncdb messages at one level lower than that requested.
< # This ensures we don't get flooded with messages during testing
< # (unless you really ask to be flooded)
< call_command('syncdb',
< verbosity=max(verbosity - 1, 0),
< interactive=False,
< database=self.connection.alias,
< load_initial_data=False)
<
< # We need to then do a flush to ensure that any data installed by
< # custom SQL has been removed. The only test data should come from
< # test fixtures, or autogenerated from post_syncdb triggers.
< # This has the side effect of loading initial data (which was
< # intentionally skipped in the syncdb).
< call_command('flush',
< verbosity=max(verbosity - 1, 0),
< interactive=False,
< database=self.connection.alias)
---
> if not skip:
> # Report syncdb messages at one level lower than that requested.
> # This ensures we don't get flooded with messages during testing
> # (unless you really ask to be flooded)
> call_command('syncdb',
> verbosity=max(verbosity - 1, 0),
> interactive=False,
> database=self.connection.alias,
> load_initial_data=False)
>
> # We need to then do a flush to ensure that any data installed by
> # custom SQL has been removed. The only test data should come from
> # test fixtures, or autogenerated from post_syncdb triggers.
> # This has the side effect of loading initial data (which was
> # intentionally skipped in the syncdb).
> call_command('flush',
> verbosity=max(verbosity - 1, 0),
> interactive=False,
> database=self.connection.alias)
391,393c395,398
< time.sleep(1)
< cursor.execute("DROP DATABASE %s"
< % self.connection.ops.quote_name(test_database_name))
---
>
> #time.sleep(1)
> #cursor.execute("DROP DATABASE %s"
> # % self.connection.ops.quote_name(test_database_name))
现在运行测试需要6秒而不是50秒。
如果修改数据库模式,则需要设置
skip = False
就一次。