Silencing deprecation warnings in the test suite

92 views
Skip to first unread message

Aymeric Augustin

unread,
Sep 2, 2013, 7:08:54 AM9/2/13
to django-d...@googlegroups.com
Hello,

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

def test_foo(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
# 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.

Thank you,

--
Aymeric.



Ramiro Morales

unread,
Sep 2, 2013, 8:41:46 PM9/2/13
to django-d...@googlegroups.com
On Mon, Sep 2, 2013 at 8:08 AM, Aymeric Augustin
<aymeric....@polytechnique.org> wrote:
> Hello,
>
> 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:
> [...]

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
e.g.:

http://ci.djangoproject.com/job/Django/database=postgres,python=python3.3/lastBuild/console

Regards,

--
Ramiro Morales
@ramiromorales

Tim Graham

unread,
Sep 3, 2013, 8:46:30 AM9/3/13
to django-d...@googlegroups.com
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. 

Tim Graham

unread,
Sep 3, 2013, 1:39:44 PM9/3/13
to django-d...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages