Mercurial > p > roundup > code
diff test/test_redis_session.py @ 7398:07f8737fe04c
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.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 24 May 2023 12:52:43 -0400 |
| parents | 75a5946cf897 |
| children | 1b7162938988 |
line wrap: on
line diff
--- a/test/test_redis_session.py Wed May 24 12:37:06 2023 -0400 +++ b/test/test_redis_session.py Wed May 24 12:52:43 2023 -0400 @@ -23,6 +23,8 @@ try: from roundup.backends.sessions_redis import Sessions, OneTimeKeys skip_redis = lambda func, *args, **kwargs: func + + from redis import AuthenticationError, ConnectionError except ImportError as e: from .pytest_patcher import mark_class skip_redis = mark_class(pytest.mark.skip( @@ -35,6 +37,11 @@ class RedisSessionTest(SessionTest): def setUp(self): + '''This must not be called if redis can not be loaded. It will + cause an error since the ConnectionError and + AuthenticationError exceptions aren't defined. + ''' + SessionTest.setUp(self) import os @@ -58,6 +65,11 @@ self.sessions = self.db.getSessionManager() self.otks = self.db.getOTKManager() + try: + self.sessions.redis.keys() + except (AuthenticationError, ConnectionError) as e: + self.skipTest('Redis server unavailable: "%s".' % e) + # database should be empty. Verify so we don't clobber # somebody's working database. self.assertEqual(self.sessions.redis.keys(), [],
