Browse Source

Fix running tests without the pytyrant library installed

Ask Solem 15 years ago
parent
commit
21e5ca23d5
2 changed files with 12 additions and 3 deletions
  1. 1 1
      celery/backends/tyrant.py
  2. 11 2
      celery/tests/test_backends/test_tyrant.py

+ 1 - 1
celery/backends/tyrant.py

@@ -6,7 +6,7 @@ from celery.loaders import settings
 try:
     import pytyrant
 except ImportError:
-    pytrant = None
+    pytyrant = None
 
 
 class Backend(KeyValueStoreBackend):

+ 11 - 2
celery/tests/test_backends/test_tyrant.py

@@ -2,6 +2,7 @@ import sys
 import unittest
 import errno
 import socket
+from celery.backends import tyrant
 from celery.backends.tyrant import Backend as TyrantBackend
 from django.conf import settings
 from celery.utils import gen_unique_id
@@ -18,14 +19,22 @@ class SomeClass(object):
 
 
 def get_tyrant_or_None():
+    def emit_no_tyrant_msg():
+        global _no_tyrant_msg_emitted
+        if not _no_tyrant_msg_emitted:
+            sys.stderr.write("\n" + _no_tyrant_msg + "\n")
+            _no_tyrant_msg_emitted = True
+
+    if tyrant.pytyrant is None:
+        emit_no_tyrant_msg()
+        return None
     try:
         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")
+                emit_no_tyrant_msg()
                 return None
             else:
                 raise