From 66f9a74b4514bd259976ce8ee3a4e78288358a5f Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sun, 21 Dec 2014 21:13:06 +0100 Subject: Added ignore_warnings decorator And removed Ignore*DeprecationWarningsMixin, now obsolete. Thanks Berker Peksag and Tim Graham for the review. --- .../writing-code/submitting-patches.txt | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'docs/internals/contributing/writing-code') diff --git a/docs/internals/contributing/writing-code/submitting-patches.txt b/docs/internals/contributing/writing-code/submitting-patches.txt index 34ae61d46f..7bc37f5a75 100644 --- a/docs/internals/contributing/writing-code/submitting-patches.txt +++ b/docs/internals/contributing/writing-code/submitting-patches.txt @@ -184,30 +184,33 @@ you need to eliminate or silence any warnings generated when running the tests. The first step is to remove any use of the deprecated behavior by Django itself. Next you can silence warnings in tests that actually test the deprecated -behavior in one of two ways: +behavior by using the ``ignore_warnings`` decorator, either at the test or class +level: #) In a particular test:: - import warnings - + from django.test import ignore_warnings from django.utils.deprecation import RemovedInDjangoXXWarning + @ignore_warnings(category=RemovedInDjangoXXWarning) def test_foo(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", category=RemovedInDjangoXXWarning) - # invoke deprecated behavior - # go ahead with the rest of the test + ... -#) For an entire test case, ``django.test.utils`` contains three helpful - mixins to silence warnings: ``IgnorePendingDeprecationWarningsMixin``, - ``IgnoreDeprecationWarningsMixin``, and - ``IgnoreAllDeprecationWarningsMixin``. For example:: +#) For an entire test case:: - from django.test.utils import IgnorePendingDeprecationWarningsMixin + from django.test import ignore_warnings + from django.utils.deprecation import RemovedInDjangoXXWarning - class MyDeprecatedTests(IgnorePendingDeprecationWarningsMixin, unittest.TestCase): + @ignore_warnings(category=RemovedInDjangoXXWarning) + class MyDeprecatedTests(unittest.TestCase): ... +.. versionchanged:: 1.8 + + Previous versions of Django had some ``Ignore*DeprecationWarningsMixin`` + classes to prevent warnings from appearing. These have been replaced by the + ``ignore_warnings`` decorator. + 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:: -- cgit v1.3