diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index 889e4d87b4..dba9fcbba8 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -228,6 +228,7 @@ class BaseDatabaseOperations: "DatabaseOperations.lookup_cast() instead." ), RemovedInDjango60Warning, + stacklevel=2, ) return "%s" diff --git a/tests/backends/base/test_operations.py b/tests/backends/base/test_operations.py index 8df02ee76b..18433352ad 100644 --- a/tests/backends/base/test_operations.py +++ b/tests/backends/base/test_operations.py @@ -239,8 +239,9 @@ class DeprecationTests(TestCase): "DatabaseOperations.field_cast_sql() is deprecated use " "DatabaseOperations.lookup_cast() instead." ) - with self.assertRaisesMessage(RemovedInDjango60Warning, msg): + with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx: base_ops.field_cast_sql("integer", "IntegerField") + self.assertEqual(ctx.filename, __file__) def test_field_cast_sql_usage_warning(self): compiler = Author.objects.all().query.get_compiler(connection.alias)