diff options
author | André Ericson <de.ericson@gmail.com> | 2019-10-29 20:27:22 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-30 13:53:22 +0100 |
commit | 972eef6b9060aee4a092bedee38a7775fbbe5d0b (patch) | |
tree | 5b6130d6d54d513389dfd180fbc6291acd303009 | |
parent | 9d15f1ead9c4bc42abcc39ba7aed5c34ade16b1f (diff) | |
download | django-972eef6b9060aee4a092bedee38a7775fbbe5d0b.tar.gz |
[2.2.x] Fixed #30927 -- Simplified an example of test for the deprecation warning with assertWarnsMessage().
Backport of 54a7b021125d23a248e70ba17bf8b10bc8619234 from master
-rw-r--r-- | docs/internals/contributing/writing-code/submitting-patches.txt | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/docs/internals/contributing/writing-code/submitting-patches.txt b/docs/internals/contributing/writing-code/submitting-patches.txt index 5bfff59b52..af0000c5d8 100644 --- a/docs/internals/contributing/writing-code/submitting-patches.txt +++ b/docs/internals/contributing/writing-code/submitting-patches.txt @@ -201,20 +201,15 @@ level: class MyDeprecatedTests(unittest.TestCase): ... -You can also add a test for the deprecation warning. You'll have to disable the -"warning as error" behavior in your test by doing:: +You can also add a test for the deprecation warning:: - import warnings + from django.utils.deprecation import RemovedInDjangoXXWarning def test_foo_deprecation_warning(self): - with warnings.catch_warnings(record=True) as warns: - warnings.simplefilter('always') # prevent warnings from appearing as errors + msg = 'Expected deprecation message' + with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg): # invoke deprecated behavior - self.assertEqual(len(warns), 1) - msg = str(warns[0].message) - self.assertEqual(msg, 'Expected deprecation message') - Finally, there are a couple of updates to Django's documentation to make: #) If the existing feature is documented, mark it deprecated in documentation |