diff options
| author | Simon Charette <charette.s@gmail.com> | 2024-08-09 13:03:24 -0400 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2024-08-28 11:47:15 -0300 |
| commit | 9a461cae3e5536cbacafa53dbd290ff68df22e67 (patch) | |
| tree | 7aea2bcfc8b8fd339341aa5c7cb6143a3b99d858 /docs | |
| parent | dd58edcc373afe57a56bf7c2374a4fc8446e80e9 (diff) | |
[5.1.x] 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.
Backport of 57307bbc7d88927989cf5b314f16d6e13ade04e6 from main.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/internals/contributing/writing-code/submitting-patches.txt | 4 |
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 2d61c6235e..c63cc6f9f0 100644 --- a/docs/internals/contributing/writing-code/submitting-patches.txt +++ b/docs/internals/contributing/writing-code/submitting-patches.txt @@ -206,9 +206,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 @@ -230,6 +231,7 @@ deprecation ends. For example:: warnings.warn( "foo() is deprecated.", category=RemovedInDjangoXXWarning, + stacklevel=2, ) old_private_helper() ... |
