|Silencing deprecation warnings in the test suite||Aymeric Augustin||9/2/13 4:08 AM|
When a feature is deprecated, it raises a PendingDeprecationWarning, either at import time or at run time. After the following release it raises DeprecationWarning. Assuming we have a good test coverage, these warnings will be shown by the test suite, with -Wall for PendingDeprecationWarning, by default for DeprecationWarning. This is annoying. The output of the test suite should remain clean.
Unfortunately, I've noticed that we often forget to silence warnings when we deprecate a feature. For instance, right new, the test suite raises warnings related to custom SQL, syncdb, and SortedDict (with -Wall). If you committed one of these deprecations, would you mind silencing the PendingDeprecationWarnings in the tests?
There are two ways to achieve that:
1) In a particular test
with warnings.catch_warnings(record=True) as w:
# frobnicate deprecated stuff
# go ahead with the test
2) For an entire test case
django.test.utils contains three helpful mixins if you want to silence warnings throughout a TestCase: IgnorePendingDeprecationWarningsMixin, IgnoreDeprecationWarningsMixin, and IgnoreAllDeprecationWarningsMixin.
|Re: Silencing deprecation warnings in the test suite||Ramiro Morales||9/2/13 5:41 PM|
On Mon, Sep 2, 2013 at 8:08 AM, Aymeric Augustin> [...]
Thanks Aymeric for raising awareness about the problem and the compact
action item description.
I plan to propose some changes that involve a deprecation cycle and
had some vague recollection about an email or ticket about the same
issue by Carl but had been unable to find it. Your mail made me search
again and luckily this time I could find it:
https://code.djangoproject.com/ticket/17049 -- Fortunately, the
recommended solution there is in the same spirit as yours.
A result of that ticket is the fact that our CI setup uses -Wall so we
can see these warnings at the console output of every configuration
|Re: Silencing deprecation warnings in the test suite||Tim Graham||9/3/13 5:46 AM|
Thanks for raising the issue. I think I committed the first and last of the three, so I'll fix those.
I've also added a ticket to document "how to deprecate a feature" in order to make these guidelines more accessible.
|Re: Silencing deprecation warnings in the test suite||Tim Graham||9/3/13 10:39 AM|
I updated the syncdb tests as well since it was straightforward. I get a clean output on Python 2.7. Python 3 still has some issues (e.g. #19905), but these aren't deprecated features.