mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #35666 -- Documented stacklevel usage and testing, and adjusted test suite accordingly.
Over the years we've had multiple instances of hit and misses when emitting warnings: either setting the wrong stacklevel or not setting it at all. This work adds assertions for the existing warnings that were declaring the correct stacklevel, but were lacking tests for it.
This commit is contained in:
parent
39abd56a7f
commit
57307bbc7d
16 changed files with 84 additions and 39 deletions
|
@ -412,15 +412,19 @@ class CheckConstraintTests(TestCase):
|
|||
def test_check_deprecation(self):
|
||||
msg = "CheckConstraint.check is deprecated in favor of `.condition`."
|
||||
condition = models.Q(foo="bar")
|
||||
with self.assertWarnsRegex(RemovedInDjango60Warning, msg):
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
|
||||
constraint = models.CheckConstraint(name="constraint", check=condition)
|
||||
with self.assertWarnsRegex(RemovedInDjango60Warning, msg):
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
|
||||
self.assertIs(constraint.check, condition)
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
other_condition = models.Q(something="else")
|
||||
with self.assertWarnsRegex(RemovedInDjango60Warning, msg):
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
|
||||
constraint.check = other_condition
|
||||
with self.assertWarnsRegex(RemovedInDjango60Warning, msg):
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
|
||||
self.assertIs(constraint.check, other_condition)
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
|
||||
def test_database_default(self):
|
||||
models.CheckConstraint(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue