diff options
| author | Simon Charette <charette.s@gmail.com> | 2021-02-14 22:42:47 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-02-24 20:31:11 +0100 |
| commit | 3089018e951dcca568574c0e0ebf9d8aab112389 (patch) | |
| tree | 932c0c26621d115185561feded6987a57771a3ea /django/test/utils.py | |
| parent | af685b5f00a2a38ec596ff905d5f70455185b6d7 (diff) | |
Fixed #32446 -- Deprecated SERIALIZE test database setting.
Whether or not the state of a test database should be serialized can be
inferred from the set of databases allowed to be access from discovered
TestCase/TransactionTestCase enabling the serialized_rollback feature
which makes this setting unnecessary.
This should make a significant test suite bootstraping time difference
on large projects that didn't explicitly disable test database
serialization.
Diffstat (limited to 'django/test/utils.py')
| -rw-r--r-- | django/test/utils.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/django/test/utils.py b/django/test/utils.py index b91532e597..c019d77354 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -25,6 +25,7 @@ from django.db.models.options import Options from django.template import Template from django.test.signals import setting_changed, template_rendered from django.urls import get_script_prefix, set_script_prefix +from django.utils.deprecation import RemovedInDjango50Warning from django.utils.translation import deactivate try: @@ -156,8 +157,18 @@ def teardown_test_environment(): del mail.outbox -def setup_databases(verbosity, interactive, *, time_keeper=None, keepdb=False, debug_sql=False, parallel=0, - aliases=None, **kwargs): +def setup_databases( + verbosity, + interactive, + *, + time_keeper=None, + keepdb=False, + debug_sql=False, + parallel=0, + aliases=None, + serialized_aliases=None, + **kwargs, +): """Create the test databases.""" if time_keeper is None: time_keeper = NullTimeKeeper() @@ -176,11 +187,29 @@ def setup_databases(verbosity, interactive, *, time_keeper=None, keepdb=False, d if first_alias is None: first_alias = alias with time_keeper.timed(" Creating '%s'" % alias): + # RemovedInDjango50Warning: when the deprecation ends, + # replace with: + # serialize_alias = serialized_aliases is None or alias in serialized_aliases + try: + serialize_alias = connection.settings_dict['TEST']['SERIALIZE'] + except KeyError: + serialize_alias = ( + serialized_aliases is None or + alias in serialized_aliases + ) + else: + warnings.warn( + 'The SERIALIZE test database setting is ' + 'deprecated as it can be inferred from the ' + 'TestCase/TransactionTestCase.databases that ' + 'enable the serialized_rollback feature.', + category=RemovedInDjango50Warning, + ) connection.creation.create_test_db( verbosity=verbosity, autoclobber=not interactive, keepdb=keepdb, - serialize=connection.settings_dict['TEST'].get('SERIALIZE', True), + serialize=serialize_alias, ) if parallel > 1: for index in range(parallel): |
