如何在Django中并行运行测试?

时间:2022-10-08 13:51:26

In my Django projects I use sqlite database to run tests. Since it uses only memory, it's much faster than MySQL, but it's still not fast enough. During tests, only one of 4 processors is used, and not much memory is consumed. So, I'd like to have 4 sqlite databases in memory to run 4 tests in parallel.

在我的Django项目中,我使用sqlite数据库来运行测试。因为它只使用内存,所以它比MySQL快得多,但它仍然不够快。在测试期间,仅使用4个处理器中的一个,并且消耗的内存不多。所以,我想在内存中有4个sqlite数据库来并行运行4个测试。

Has anyone tried this?

有没人试过这个?

3 个解决方案

#1


16  

Since Django 1.9 it's possible to run the tests in parallel by Django with its built-in unit-test features.

从Django 1.9开始,Django可以通过内置的单元测试功能并行运行测试。

Django Docs: https://docs.djangoproject.com/en/1.9/ref/django-admin/#django-admin-option---parallel

Django Docs:https://docs.djangoproject.com/en/1.9/ref/django-admin/#django-admin-option---parallel

#2


2  

You can use a parallel test runner for Django and Twisted described here: http://www.tomaz.me/2011/04/03/making-django-and-twisted-tests-faster.html (the source lives here https://github.com/Kami/parallel-django-and-twisted-test-runner - link at the end of the post). You can use it as described in Django docs on testing.

你可以使用Django和Twisted的并行测试运行器来描述:http://www.tomaz.me/2011/04/03/making-django-and-twisted-tests-faster.html(源码存在于此处https: //github.com/Kami/parallel-django-and-twisted-test-runner - 帖子末尾的链接)。您可以按照Django docs中的测试使用它。

There is also a nose parallel test runner.

还有一个鼻子平行测试跑步者。

#3


-2  

You can easily split the testing for apps on parrallalel on linux by:

您可以通过以下方式轻松地在Linux上的parrallalel上拆分应用程序的测试:

$ python manage.py test cms & \
python manage.py test blog & \
python manage.py test store & \
python manage.py test registration
$ 

Could be helpfull for big projects with a lot of apps, the best would be a bash scripts that runs tests every four apps.

对于包含大量应用程序的大型项目可能会有所帮助,最好的是每四个应用程序运行测试的bash脚本。

#1


16  

Since Django 1.9 it's possible to run the tests in parallel by Django with its built-in unit-test features.

从Django 1.9开始,Django可以通过内置的单元测试功能并行运行测试。

Django Docs: https://docs.djangoproject.com/en/1.9/ref/django-admin/#django-admin-option---parallel

Django Docs:https://docs.djangoproject.com/en/1.9/ref/django-admin/#django-admin-option---parallel

#2


2  

You can use a parallel test runner for Django and Twisted described here: http://www.tomaz.me/2011/04/03/making-django-and-twisted-tests-faster.html (the source lives here https://github.com/Kami/parallel-django-and-twisted-test-runner - link at the end of the post). You can use it as described in Django docs on testing.

你可以使用Django和Twisted的并行测试运行器来描述:http://www.tomaz.me/2011/04/03/making-django-and-twisted-tests-faster.html(源码存在于此处https: //github.com/Kami/parallel-django-and-twisted-test-runner - 帖子末尾的链接)。您可以按照Django docs中的测试使用它。

There is also a nose parallel test runner.

还有一个鼻子平行测试跑步者。

#3


-2  

You can easily split the testing for apps on parrallalel on linux by:

您可以通过以下方式轻松地在Linux上的parrallalel上拆分应用程序的测试:

$ python manage.py test cms & \
python manage.py test blog & \
python manage.py test store & \
python manage.py test registration
$ 

Could be helpfull for big projects with a lot of apps, the best would be a bash scripts that runs tests every four apps.

对于包含大量应用程序的大型项目可能会有所帮助,最好的是每四个应用程序运行测试的bash脚本。