diff --git a/django/test/signals.py b/django/test/signals.py
index e531cd72f5..cb78b76114 100644
--- a/django/test/signals.py
+++ b/django/test/signals.py
@@ -202,6 +202,14 @@ def static_finders_changed(*, setting, **kwargs):
get_finder.cache_clear()
+@receiver(setting_changed)
+def form_renderer_changed(*, setting, **kwargs):
+ if setting == "FORM_RENDERER":
+ from django.forms.renderers import get_default_renderer
+
+ get_default_renderer.cache_clear()
+
+
@receiver(setting_changed)
def auth_password_validators_changed(*, setting, **kwargs):
if setting == "AUTH_PASSWORD_VALIDATORS":
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 89c914a864..4eaffdb331 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -1502,11 +1502,17 @@ Overridden settings Data reset
================================= ========================
USE_TZ, TIME_ZONE Databases timezone
TEMPLATES Template engines
+FORM_RENDERER Default renderer
SERIALIZATION_MODULES Serializers cache
LOCALE_PATHS, LANGUAGE_CODE Default translation and loaded translations
STATIC_ROOT, STATIC_URL, STORAGES Storages configuration
================================= ========================
+.. versionchanged:: 5.1
+
+ Resetting the default renderer when the ``FORM_RENDERER`` setting is
+ changed was added.
+
Isolating apps
--------------
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index 547f58632f..877571726d 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -5145,7 +5145,6 @@ class OverrideTests(SimpleTestCase):
class Person(Form):
first_name = CharField()
- get_default_renderer.cache_clear()
t = Template("{{ form }}")
html = t.render(Context({"form": Person()}))
expected = """
@@ -5153,14 +5152,12 @@ class OverrideTests(SimpleTestCase):
"""
self.assertHTMLEqual(html, expected)
- get_default_renderer.cache_clear()
@override_settings(FORM_RENDERER="forms_tests.tests.test_forms.CustomRenderer")
def test_custom_renderer_field_template_name(self):
class Person(Form):
first_name = CharField()
- get_default_renderer.cache_clear()
t = Template("{{ form.first_name.as_field_group }}")
html = t.render(Context({"form": Person()}))
expected = """
@@ -5169,7 +5166,6 @@ class OverrideTests(SimpleTestCase):
"""
self.assertHTMLEqual(html, expected)
- get_default_renderer.cache_clear()
def test_per_form_template_name(self):
class Person(Form):
diff --git a/tests/template_tests/test_autoreloader.py b/tests/template_tests/test_autoreloader.py
index 2336f4e6f8..1eac0a54d6 100644
--- a/tests/template_tests/test_autoreloader.py
+++ b/tests/template_tests/test_autoreloader.py
@@ -1,7 +1,6 @@
from pathlib import Path
from unittest import mock
-from django.forms.renderers import get_default_renderer
from django.template import autoreload
from django.test import SimpleTestCase, override_settings
from django.test.utils import require_jinja2
@@ -74,8 +73,6 @@ class TemplateReloadTests(SimpleTestCase):
def test_form_template_reset_template_change_no_djangotemplates(
self, mock_loader_reset
):
- self.addCleanup(get_default_renderer.cache_clear)
- get_default_renderer.cache_clear()
template_path = Path(__file__).parent / "templates" / "index.html"
self.assertIs(autoreload.template_changed(None, template_path), True)
mock_loader_reset.assert_not_called()