summaryrefslogtreecommitdiff
path: root/docs/internals/contributing/writing-code
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2024-08-09 13:03:24 -0400
committernessita <124304+nessita@users.noreply.github.com>2024-08-28 11:44:05 -0300
commit57307bbc7d88927989cf5b314f16d6e13ade04e6 (patch)
tree2f110306223f71903fbe38a35bedeb898d38677a /docs/internals/contributing/writing-code
parent39abd56a7fb1e2f735040df0fdfc08f57d91a49b (diff)
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.
Diffstat (limited to 'docs/internals/contributing/writing-code')
-rw-r--r--docs/internals/contributing/writing-code/submitting-patches.txt4
1 files changed, 3 insertions, 1 deletions
diff --git a/docs/internals/contributing/writing-code/submitting-patches.txt b/docs/internals/contributing/writing-code/submitting-patches.txt
index 6a5c68f573..cac6848d04 100644
--- a/docs/internals/contributing/writing-code/submitting-patches.txt
+++ b/docs/internals/contributing/writing-code/submitting-patches.txt
@@ -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()
...