summaryrefslogtreecommitdiff
path: root/tests/__init__.py
diff options
context:
space:
mode:
authorVincent Driessen <vincent@3rdcloud.com>2012-02-13 09:06:39 +0100
committerVincent Driessen <vincent@3rdcloud.com>2012-02-13 09:08:33 +0100
commit39f106cdb305cf5dd5d9e634c7d56772934c06ad (patch)
tree4e316534b01cb3217b701402208925bf0adce3c9 /tests/__init__.py
parent90a458ca8e33459365db808abc4d1e7da44e7162 (diff)
downloadrq-39f106cdb305cf5dd5d9e634c7d56772934c06ad.tar.gz
Have the test suite find an empty Redis database.
Since the test suite `flushdb()`'s after running each test, we should make sure the database is empty before we even start running tests. This patch will make sure to never destroy any local production data inside the running Redis instance. This fixes #25.
Diffstat (limited to 'tests/__init__.py')
-rw-r--r--tests/__init__.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
index b912bed..b833a91 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -14,6 +14,18 @@ def failing_job(x):
return x / 0
+def find_empty_redis_database():
+ """Tries to connect to a random Redis database (starting from 4), and
+ will use/connect it when no keys are in there.
+ """
+ for dbnum in range(4, 17):
+ testconn = Redis(db=dbnum)
+ empty = len(testconn.keys('*')) == 0
+ if empty:
+ return testconn
+ assert False, 'No empty Redis database found to run tests in.'
+
+
class RQTestCase(unittest.TestCase):
"""Base class to inherit test cases from for RQ.
@@ -27,7 +39,7 @@ class RQTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Set up connection to Redis
- testconn = Redis()
+ testconn = find_empty_redis_database()
conn.push(testconn)
# Store the connection (for sanity checking)