Setting up django parallel test in settings.py file
Hello, I know that it is possible to run tests in django in parallel using a flag --parallel
, for example. python manage.py test --parallel 10
... This really speeds up testing on a project I'm working on, which is really nice. But the developers in the company have different hardware settings. So ideally I would like to put the parallel argument in ./app_name/settings.py
so that every developer uses at least 4 threads in testing, or the number of cores provided by the multiprocessing lib.
I know I can make another script let say run_test.py
that I am using --parallel
, but I would like to make parallel testing "invisible".
To summarize - my question is, can I put the number of parallel test runs in my django app settings? And if yes, then yes. The second question is whether the command line argument (X) will manage.py --parallel X
override the settings from "./app_name/settings"
Any help is greatly appreciated.
source to share
There are no settings for this, but you can override the command test
to set a different default. In one of the installed applications, create a submodule .management.commands
and add the file test.py
. There you need to subclass the old test command:
from django.conf import settings
from django.core.management.commands.test import Command as TestCommand
class Command(TestCommand):
def add_arguments(self, parser):
super().add_arguments(parser)
if hasattr(settings, 'TEST_PARALLEL_PROCESSES'):
parser.set_defaults(parallel=settings.TEST_PARALLEL_PROCESSES)
This adds a new default flag to the icon --parallel
. The launch python manage.py test --parallel=1
will still override the default.
source to share