{{{
import warnings
def test_foo_deprecation_warning(self):
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always') # prevent warnings from appearing
as errors
# invoke deprecated behavior
self.assertEqual(len(warns), 1)
msg = str(warns[0].message)
self.assertEqual(msg, 'Expected deprecation message')
}}}
This could be simplified as suggested here:
https://github.com/django/django/pull/11905#discussion_r334984986
My suggestion is that we change the documentation to avoid unnecessary
extra work.
--
Ticket URL: <https://code.djangoproject.com/ticket/30927>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => André Ericson
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/30927#comment:1>
--
Ticket URL: <https://code.djangoproject.com/ticket/30927#comment:2>
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/30927#comment:3>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30927#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"54a7b021125d23a248e70ba17bf8b10bc8619234" 54a7b021]:
{{{
#!CommitTicketReference repository=""
revision="54a7b021125d23a248e70ba17bf8b10bc8619234"
Fixed #30927 -- Simplified an example of test for the deprecation warning
with assertWarnsMessage().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30927#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"3c5f8313c21f095feca8c44207e768fe0adfa0fa" 3c5f8313]:
{{{
#!CommitTicketReference repository=""
revision="3c5f8313c21f095feca8c44207e768fe0adfa0fa"
[3.0.x] Fixed #30927 -- Simplified an example of test for the deprecation
warning with assertWarnsMessage().
Backport of 54a7b021125d23a248e70ba17bf8b10bc8619234 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30927#comment:6>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"972eef6b9060aee4a092bedee38a7775fbbe5d0b" 972eef6b]:
{{{
#!CommitTicketReference repository=""
revision="972eef6b9060aee4a092bedee38a7775fbbe5d0b"
[2.2.x] Fixed #30927 -- Simplified an example of test for the deprecation
warning with assertWarnsMessage().
Backport of 54a7b021125d23a248e70ba17bf8b10bc8619234 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30927#comment:7>