mirror of
https://github.com/django/django.git
synced 2025-01-03 15:06:09 +00:00
Fixed #30927 -- Simplified an example of test for the deprecation warning with assertWarnsMessage().
This commit is contained in:
parent
6315a272c5
commit
54a7b02112
@ -200,20 +200,15 @@ level:
|
|||||||
class MyDeprecatedTests(unittest.TestCase):
|
class MyDeprecatedTests(unittest.TestCase):
|
||||||
...
|
...
|
||||||
|
|
||||||
You can also add a test for the deprecation warning. You'll have to disable the
|
You can also add a test for the deprecation warning::
|
||||||
"warning as error" behavior in your test by doing::
|
|
||||||
|
|
||||||
import warnings
|
from django.utils.deprecation import RemovedInDjangoXXWarning
|
||||||
|
|
||||||
def test_foo_deprecation_warning(self):
|
def test_foo_deprecation_warning(self):
|
||||||
with warnings.catch_warnings(record=True) as warns:
|
msg = 'Expected deprecation message'
|
||||||
warnings.simplefilter('always') # prevent warnings from appearing as errors
|
with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg):
|
||||||
# invoke deprecated behavior
|
# 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:
|
Finally, there are a couple of updates to Django's documentation to make:
|
||||||
|
|
||||||
#) If the existing feature is documented, mark it deprecated in documentation
|
#) If the existing feature is documented, mark it deprecated in documentation
|
||||||
|
Loading…
Reference in New Issue
Block a user