Kaydet (Commit) 9f427617 authored tarafından Diego Guimarães's avatar Diego Guimarães Kaydeden (comit) Tim Graham

Refs #23947 -- Worked around a bug in Python that prevents deprecation warnings…

Refs #23947 -- Worked around a bug in Python that prevents deprecation warnings from appearing in tests.
üst 1917017b
...@@ -541,3 +541,17 @@ def captured_stdin(): ...@@ -541,3 +541,17 @@ def captured_stdin():
self.assertEqual(captured, "hello") self.assertEqual(captured, "hello")
""" """
return captured_output("stdin") 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()
...@@ -5,6 +5,7 @@ import unittest ...@@ -5,6 +5,7 @@ import unittest
import warnings import warnings
from django.test import SimpleTestCase, RequestFactory, override_settings 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 import six, translation
from django.utils.deprecation import RenameMethodsBase from django.utils.deprecation import RenameMethodsBase
from django.utils.encoding import force_text from django.utils.encoding import force_text
...@@ -28,6 +29,7 @@ class RenameMethodsTests(SimpleTestCase): ...@@ -28,6 +29,7 @@ class RenameMethodsTests(SimpleTestCase):
Ensure a warning is raised upon class definition to suggest renaming Ensure a warning is raised upon class definition to suggest renaming
the faulty method. the faulty method.
""" """
reset_warning_registry()
with warnings.catch_warnings(record=True) as recorded: with warnings.catch_warnings(record=True) as recorded:
warnings.simplefilter('always') warnings.simplefilter('always')
......
...@@ -5,6 +5,7 @@ from unittest import skipUnless ...@@ -5,6 +5,7 @@ from unittest import skipUnless
import warnings import warnings
from django.test import SimpleTestCase from django.test import SimpleTestCase
from django.test.utils import reset_warning_registry
from django.utils import six, text from django.utils import six, text
from django.utils.deprecation import RemovedInDjango19Warning from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.encoding import force_text from django.utils.encoding import force_text
...@@ -219,6 +220,7 @@ class TestUtilsText(SimpleTestCase): ...@@ -219,6 +220,7 @@ class TestUtilsText(SimpleTestCase):
self.assertEqual(text.javascript_quote(input), output) self.assertEqual(text.javascript_quote(input), output)
def test_deprecation(self): def test_deprecation(self):
reset_warning_registry()
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always") warnings.simplefilter("always")
text.javascript_quote('thingy') text.javascript_quote('thingy')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment