diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-12-21 21:13:06 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-12-30 18:16:25 +0100 |
| commit | 66f9a74b4514bd259976ce8ee3a4e78288358a5f (patch) | |
| tree | 4a3f5c24b15f53e9a886788110c735e0822783f9 /docs/internals/contributing/writing-code/submitting-patches.txt | |
| parent | 8082c75d188e395c973f52bfdf5d547c741edd03 (diff) | |
Added ignore_warnings decorator
And removed Ignore*DeprecationWarningsMixin, now obsolete.
Thanks Berker Peksag and Tim Graham for the review.
Diffstat (limited to 'docs/internals/contributing/writing-code/submitting-patches.txt')
| -rw-r--r-- | docs/internals/contributing/writing-code/submitting-patches.txt | 29 |
1 files changed, 16 insertions, 13 deletions
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:: |
