Parcourir la source

Move module import side-effects in celery.tests to a unittest setup function. Closes #1237

Ask Solem il y a 12 ans
Parent
commit
bd2113c7cc
1 fichiers modifiés avec 18 ajouts et 16 suppressions
  1. 18 16
      celery/tests/__init__.py

+ 18 - 16
celery/tests/__init__.py

@@ -7,16 +7,6 @@ import warnings
 
 from importlib import import_module
 
-config_module = os.environ.setdefault('CELERY_TEST_CONFIG_MODULE',
-                                      'celery.tests.config')
-
-os.environ.setdefault('CELERY_CONFIG_MODULE', config_module)
-os.environ['CELERY_LOADER'] = 'default'
-os.environ['EVENTLET_NOPATCH'] = 'yes'
-os.environ['GEVENT_NOPATCH'] = 'yes'
-os.environ['KOMBU_DISABLE_LIMIT_PROTECTION'] = 'yes'
-os.environ['CELERY_BROKER_URL'] = 'memory://'
-
 try:
     WindowsError = WindowsError  # noqa
 except NameError:
@@ -25,6 +15,24 @@ except NameError:
         pass
 
 
+def setup():
+    config_module = os.environ.setdefault(
+        'CELERY_TEST_CONFIG_MODULE', 'celery.tests.config',
+    )
+
+    os.environ.setdefault('CELERY_CONFIG_MODULE', config_module)
+    os.environ['CELERY_LOADER'] = 'default'
+    os.environ['EVENTLET_NOPATCH'] = 'yes'
+    os.environ['GEVENT_NOPATCH'] = 'yes'
+    os.environ['KOMBU_DISABLE_LIMIT_PROTECTION'] = 'yes'
+    os.environ['CELERY_BROKER_URL'] = 'memory://'
+
+    if os.environ.get('COVER_ALL_MODULES') or '--with-coverage3' in sys.argv:
+        with warnings.catch_warnings(record=True):
+            import_all_modules()
+        warnings.resetwarnings()
+
+
 def teardown():
     # Don't want SUBDEBUG log messages at finalization.
     try:
@@ -76,9 +84,3 @@ def import_all_modules(name=__name__, file=__file__,
                 import_module(module)
             except ImportError:
                 pass
-
-
-if os.environ.get('COVER_ALL_MODULES') or '--with-coverage3' in sys.argv:
-    with warnings.catch_warnings(record=True):
-        import_all_modules()
-    warnings.resetwarnings()