Fix RuntimeError on sys.modules in reset_warning_registry

Django 1.8's reset_warning_registry (which we backport)
was generating `RuntimeError: dictionary changed size
during iteration` in Travis tests under Python 3.x.

Likely a thread-safety issue on sys.modules.values().
See https://code.djangoproject.com/ticket/21049
for fix applied elsewhere in Django.
This commit is contained in:
medmunds
2015-05-12 18:42:12 -07:00
parent fd75c4b24d
commit 8db86a8274

View File

@@ -91,6 +91,7 @@ class BackportedAssertions(object):
# Backport from Django 1.8 (django.test.utils) # Backport from Django 1.8 (django.test.utils)
# with fix suggested by https://code.djangoproject.com/ticket/21049
def reset_warning_registry(): def reset_warning_registry():
""" """
Clear warning registry for all modules. This is required in some tests Clear warning registry for all modules. This is required in some tests
@@ -100,6 +101,6 @@ def reset_warning_registry():
The bug was fixed in Python 3.4.2. The bug was fixed in Python 3.4.2.
""" """
key = "__warningregistry__" key = "__warningregistry__"
for mod in sys.modules.values(): for mod in list(sys.modules.values()):
if hasattr(mod, key): if hasattr(mod, key):
getattr(mod, key).clear() getattr(mod, key).clear()