فهرست منبع

Added check to see if Tyrant is setup in setting files, if not skip test

Vitaly Babiy 16 سال پیش
والد
کامیت
84ca58d0ff
2فایلهای تغییر یافته به همراه16 افزوده شده و 11 حذف شده
  1. 2 1
      celery/backends/tyrant.py
  2. 14 10
      celery/tests/test_backends/test_tyrant.py

+ 2 - 1
celery/backends/tyrant.py

@@ -37,7 +37,8 @@ class Backend(KeyValueStoreBackend):
                             getattr(settings, "TT_HOST", self.tyrant_host)
         self.tyrant_port = tyrant_port or \
                             getattr(settings, "TT_PORT", self.tyrant_port)
-        self.tyrant_port = int(self.tyrant_port)
+        if self.tyrant_port:
+            self.tyrant_port = int(self.tyrant_port)
         if not self.tyrant_host or not self.tyrant_port:
             raise ImproperlyConfigured(
                 "To use the Tokyo Tyrant backend, you have to "

+ 14 - 10
celery/tests/test_backends/test_tyrant.py

@@ -5,6 +5,7 @@ import socket
 from celery.backends.tyrant import Backend as TyrantBackend
 from django.conf import settings
 from celery.utils import gen_unique_id
+from django.core.exceptions import ImproperlyConfigured
 
 _no_tyrant_msg = "* Tokyo Tyrant not running. Will not execute related tests."
 _no_tyrant_msg_emitted = False
@@ -17,17 +18,20 @@ class SomeClass(object):
 
 
 def get_tyrant_or_None():
-    tb = TyrantBackend()
     try:
-        tb.open()
-    except socket.error, exc:
-        if exc.errno == errno.ECONNREFUSED:
-            if not _no_tyrant_msg_emitted:
-                sys.stderr.write("\n" + _no_tyrant_msg + "\n")
-            return None
-        else:
-            raise
-    return tb
+        tb = TyrantBackend()
+        try:
+            tb.open()
+        except socket.error, exc:
+            if exc.errno == errno.ECONNREFUSED:
+                if not _no_tyrant_msg_emitted:
+                    sys.stderr.write("\n" + _no_tyrant_msg + "\n")
+                return None
+            else:
+                raise
+        return tb
+    except ImproperlyConfigured, exc:
+        return None
 
 
 class TestTyrantBackend(unittest.TestCase):