Skip to content

Commit 73213aa

Browse files
committed
Skip redis tests if unable to communicate with the server.
If the redis module is in the test environment, the redis tests will not be skipped. If connecting to redis during testing fails with a ConnectionError because there is no redis server at localhost, or if it fails with an AuthenticationError, you would fail a slew of tests. This causes the tests to report as skipped if either of the two errors occurs. It is very inefficient as it fails in setup() for the tests, but at least it does report skipping the tests. Also documented how to pass the redis password to the tests in the test part of the install docs. Future note: running tests needs proper docs in development.txt (including database setup) and a link left to that doc in installation.txt.
1 parent 596903a commit 73213aa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/test_redis_session.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
try:
2424
from roundup.backends.sessions_redis import Sessions, OneTimeKeys
2525
skip_redis = lambda func, *args, **kwargs: func
26+
27+
from redis import AuthenticationError, ConnectionError
2628
except ImportError as e:
2729
from .pytest_patcher import mark_class
2830
skip_redis = mark_class(pytest.mark.skip(
@@ -35,6 +37,11 @@
3537

3638
class RedisSessionTest(SessionTest):
3739
def setUp(self):
40+
'''This must not be called if redis can not be loaded. It will
41+
cause an error since the ConnectionError and
42+
AuthenticationError exceptions aren't defined.
43+
'''
44+
3845
SessionTest.setUp(self)
3946

4047
import os
@@ -58,6 +65,11 @@ def setUp(self):
5865
self.sessions = self.db.getSessionManager()
5966
self.otks = self.db.getOTKManager()
6067

68+
try:
69+
self.sessions.redis.keys()
70+
except (AuthenticationError, ConnectionError) as e:
71+
self.skipTest('Redis server unavailable: "%s".' % e)
72+
6173
# database should be empty. Verify so we don't clobber
6274
# somebody's working database.
6375
self.assertEqual(self.sessions.redis.keys(), [],

0 commit comments

Comments
 (0)