diff --git a/django/contrib/auth/tests/test_auth_backends.py b/django/contrib/auth/tests/test_auth_backends.py index 73fabe11b0..383fae759e 100644 --- a/django/contrib/auth/tests/test_auth_backends.py +++ b/django/contrib/auth/tests/test_auth_backends.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals from datetime import date -from django.conf import settings from django.contrib.auth.backends import ModelBackend from django.contrib.auth.models import User, Group, Permission, AnonymousUser from django.contrib.auth.tests.utils import skipIfCustomUser @@ -34,12 +33,14 @@ class BaseModelBackendTest(object): backend = 'django.contrib.auth.backends.ModelBackend' def setUp(self): - self.curr_auth = list(settings.AUTHENTICATION_BACKENDS) - settings.AUTHENTICATION_BACKENDS = [self.backend] + self.patched_settings = modify_settings( + AUTHENTICATION_BACKENDS={'append': self.backend}, + ) + self.patched_settings.enable() self.create_users() def tearDown(self): - settings.AUTHENTICATION_BACKENDS = self.curr_auth + self.patched_settings.disable() # The custom_perms test messes with ContentTypes, which will # be cached; flush the cache to ensure there are no side effects # Refs #14975, #14925 diff --git a/django/contrib/auth/tests/test_remote_user.py b/django/contrib/auth/tests/test_remote_user.py index 4e6f86fd0c..6f7de6f2ef 100644 --- a/django/contrib/auth/tests/test_remote_user.py +++ b/django/contrib/auth/tests/test_remote_user.py @@ -6,7 +6,7 @@ from django.contrib.auth.backends import RemoteUserBackend from django.contrib.auth.middleware import RemoteUserMiddleware from django.contrib.auth.models import User from django.contrib.auth.tests.utils import skipIfCustomUser -from django.test import TestCase, override_settings +from django.test import TestCase, modify_settings, override_settings from django.utils import timezone @@ -23,15 +23,14 @@ class RemoteUserTest(TestCase): known_user2 = 'knownuser2' def setUp(self): - self.curr_middleware = list(settings.MIDDLEWARE_CLASSES) - self.curr_auth = list(settings.AUTHENTICATION_BACKENDS) - settings.MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES + [self.middleware] - settings.AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS + [self.backend] + self.patched_settings = modify_settings( + AUTHENTICATION_BACKENDS={'append': self.backend}, + MIDDLEWARE_CLASSES={'append': self.middleware}, + ) + self.patched_settings.enable() def tearDown(self): - """Restores settings to avoid breaking other tests.""" - settings.MIDDLEWARE_CLASSES = self.curr_middleware - settings.AUTHENTICATION_BACKENDS = self.curr_auth + self.patched_settings.disable() def test_no_remote_user(self): """