diff --git a/django/forms/renderers.py b/django/forms/renderers.py index 970d05804c..baf8f74507 100644 --- a/django/forms/renderers.py +++ b/django/forms/renderers.py @@ -80,6 +80,7 @@ class DjangoDivFormRenderer(DjangoTemplates): "The DjangoDivFormRenderer transitional form renderer is deprecated. Use " "DjangoTemplates instead.", RemovedInDjango60Warning, + stacklevel=2, ) super().__init__(*args, **kwargs) @@ -96,6 +97,7 @@ class Jinja2DivFormRenderer(Jinja2): "The Jinja2DivFormRenderer transitional form renderer is deprecated. Use " "Jinja2 instead.", RemovedInDjango60Warning, + stacklevel=2, ) super().__init__(*args, **kwargs) diff --git a/tests/forms_tests/tests/test_renderers.py b/tests/forms_tests/tests/test_renderers.py index dbde6df49d..3c1d8bb8ea 100644 --- a/tests/forms_tests/tests/test_renderers.py +++ b/tests/forms_tests/tests/test_renderers.py @@ -64,16 +64,18 @@ class DeprecationTests(SimpleTestCase): "The DjangoDivFormRenderer transitional form renderer is deprecated. Use " "DjangoTemplates instead." ) - with self.assertRaisesMessage(RemovedInDjango60Warning, msg): + with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: DjangoDivFormRenderer() + self.assertEqual(ctx.filename, __file__) def test_jinja2_div_renderer_warning(self): msg = ( "The Jinja2DivFormRenderer transitional form renderer is deprecated. Use " "Jinja2 instead." ) - with self.assertRaisesMessage(RemovedInDjango60Warning, msg): + with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: Jinja2DivFormRenderer() + self.assertEqual(ctx.filename, __file__) @ignore_warnings(category=RemovedInDjango60Warning) def test_deprecation_renderers_can_be_instantiated(self):