Browse Source

Djangos new MovedModule is messing with assertWarnsRegex

Ask Solem 11 years ago
parent
commit
9cd36064e7
1 changed files with 10 additions and 2 deletions
  1. 10 2
      celery/tests/case.py

+ 10 - 2
celery/tests/case.py

@@ -44,6 +44,12 @@ from celery.five import (
 from celery.utils.functional import noop
 from celery.utils.imports import qualname
 
+try:  # pragma: no cover
+    from django.utils.six import MovedModule
+except ImportError:  # pragma: no cover
+    class MovedModule(object):  # noqa
+        pass
+
 __all__ = [
     'Case', 'AppCase', 'Mock', 'MagicMock', 'ANY',
     'patch', 'call', 'sentinel', 'skip_unless_module',
@@ -202,8 +208,10 @@ class _AssertWarnsContext(_AssertRaisesBaseContext):
         # to work properly.
         warnings.resetwarnings()
         for v in list(values(sys.modules)):
-            if getattr(v, '__warningregistry__', None):
-                v.__warningregistry__ = {}
+            # do not evaluate Django moved modules:
+            if not isinstance(v, MovedModule):
+                if getattr(v, '__warningregistry__', None):
+                    v.__warningregistry__ = {}
         self.warnings_manager = warnings.catch_warnings(record=True)
         self.warnings = self.warnings_manager.__enter__()
         warnings.simplefilter('always', self.expected)