mirror of
https://github.com/django/django.git
synced 2025-07-24 21:54:14 +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
|
@ -209,9 +209,10 @@ You should also add a test for the deprecation warning::
|
|||
|
||||
def test_foo_deprecation_warning(self):
|
||||
msg = "Expected deprecation message"
|
||||
with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg):
|
||||
with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg) as ctx:
|
||||
# invoke deprecated behavior
|
||||
...
|
||||
self.assertEqual(ctx.filename, __file__)
|
||||
|
||||
It's important to include a ``RemovedInDjangoXXWarning`` comment above code
|
||||
which has no warning reference, but will need to be changed or removed when the
|
||||
|
@ -233,6 +234,7 @@ deprecation ends. For example::
|
|||
warnings.warn(
|
||||
"foo() is deprecated.",
|
||||
category=RemovedInDjangoXXWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
old_private_helper()
|
||||
...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue