Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run tests in parallel in Django?

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.

Has anyone tried this?

like image 694
lfagundes Avatar asked Mar 14 '11 20:03

lfagundes


People also ask

How do I run a parallel test in Django?

So you can use the following command to execute the tests in parallel. You can adjust the number of processes either by providing it as the option's value, e.g. --parallel=4, or by setting the DJANGO_TEST_PROCESSES environment variable.

Is Django parallel?

Running tests in parallelBy default, Django runs tests sequentially. However, whether you're running tests locally or in your CI (Github Actions, Jenkins CI, etc) more often than not you'll have multiple cores.

Do Pytest tests run in parallel?

Learn Pytest From Scratch By default, pytest runs tests in sequential order. In a real scenario, a test suite will have a number of test files and each file will have a bunch of tests. This will lead to a large execution time. To overcome this, pytest provides us with an option to run tests in parallel.


2 Answers

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

Django Docs: https://docs.djangoproject.com/en/3.0/ref/django-admin/#cmdoption-test-parallel

like image 52
Alireza Savand Avatar answered Sep 21 '22 23:09

Alireza Savand


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.

There is also a nose parallel test runner.

like image 41
Konstantin Lopuhin Avatar answered Sep 20 '22 23:09

Konstantin Lopuhin