summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego GuimarĂ£es <diegobr.sistemas@gmail.com>2014-12-05 18:14:20 -0200
committerTim Graham <timograham@gmail.com>2014-12-06 14:46:01 -0500
commit9f427617e4559012e1c2fd8fce46cbe225d8515d (patch)
tree852a64644d99d125d8c90099ffc1408bd12a61c2
parent1917017b8d38a9c330456cbdf2e81b0dc49e6477 (diff)
Refs #23947 -- Worked around a bug in Python that prevents deprecation warnings from appearing in tests.
-rw-r--r--django/test/utils.py14
-rw-r--r--tests/deprecation/tests.py2
-rw-r--r--tests/utils_tests/test_text.py2
3 files changed, 18 insertions, 0 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index dc1754dbff..3d9a0d3526 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -541,3 +541,17 @@ def captured_stdin():
self.assertEqual(captured, "hello")
"""
return captured_output("stdin")
+
+
+def reset_warning_registry():
+ """
+ Clear warning registry for all modules. This is required in some tests
+ because of a bug in Python that prevents warnings.simplefilter("always")
+ from always making warnings appear: http://bugs.python.org/issue4180
+
+ The bug was fixed in Python 3.4.2.
+ """
+ key = "__warningregistry__"
+ for mod in sys.modules.values():
+ if hasattr(mod, key):
+ getattr(mod, key).clear()
diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py
index 79a6284cf6..dcd50a6d11 100644
--- a/tests/deprecation/tests.py
+++ b/tests/deprecation/tests.py
@@ -5,6 +5,7 @@ import unittest
import warnings
from django.test import SimpleTestCase, RequestFactory, override_settings
+from django.test.utils import reset_warning_registry
from django.utils import six, translation
from django.utils.deprecation import RenameMethodsBase
from django.utils.encoding import force_text
@@ -28,6 +29,7 @@ class RenameMethodsTests(SimpleTestCase):
Ensure a warning is raised upon class definition to suggest renaming
the faulty method.
"""
+ reset_warning_registry()
with warnings.catch_warnings(record=True) as recorded:
warnings.simplefilter('always')
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py
index 4ef30314cf..f315cf41ce 100644
--- a/tests/utils_tests/test_text.py
+++ b/tests/utils_tests/test_text.py
@@ -5,6 +5,7 @@ from unittest import skipUnless
import warnings
from django.test import SimpleTestCase
+from django.test.utils import reset_warning_registry
from django.utils import six, text
from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.encoding import force_text
@@ -219,6 +220,7 @@ class TestUtilsText(SimpleTestCase):
self.assertEqual(text.javascript_quote(input), output)
def test_deprecation(self):
+ reset_warning_registry()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
text.javascript_quote('thingy')