社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

guettli

guettli 最近创建的主题
guettli 最近回复了
5 年前
回复了 guettli 创建的主题 » Django 1.4:测试非常缓慢

你可以破解这个选项 --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 就一次。