Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit f97cf42

Browse files
committed
Skip Redis test if Redis not installed
1 parent 25698fa commit f97cf42

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

tests/replication/tcp/test_redis.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from synapse.replication.tcp.redis import RedisDirectTcpReplicationClientFactory
15+
try:
16+
# We only import it to see if it's installed, so ignore the 'unused' import
17+
import txredisapi # noqa: F401
18+
19+
HAVE_TXREDISAPI = True
20+
except ImportError:
21+
HAVE_TXREDISAPI = False
1622

1723
from tests.replication._base import BaseMultiWorkerStreamTestCase
1824
from tests.unittest import HomeserverTestCase
@@ -38,7 +44,12 @@
3844

3945

4046
class RedisTestCase(HomeserverTestCase):
47+
if not HAVE_TXREDISAPI:
48+
skip = "Redis extras not installed"
49+
4150
def test_subscribed_to_enough_redis_channels(self) -> None:
51+
from synapse.replication.tcp.redis import RedisDirectTcpReplicationClientFactory
52+
4253
# The default main process is subscribed to USER_IP and all RDATA channels.
4354
self.assertCountEqual(
4455
RedisDirectTcpReplicationClientFactory.channels_to_subscribe_to_for_config(
@@ -52,7 +63,12 @@ def test_subscribed_to_enough_redis_channels(self) -> None:
5263

5364

5465
class RedisWorkerTestCase(BaseMultiWorkerStreamTestCase):
66+
if not HAVE_TXREDISAPI:
67+
skip = "Redis extras not installed"
68+
5569
def test_background_worker_subscribed_to_user_ip(self) -> None:
70+
from synapse.replication.tcp.redis import RedisDirectTcpReplicationClientFactory
71+
5672
# The default main process is subscribed to USER_IP and all RDATA channels.
5773
worker1 = self.make_worker_hs(
5874
"synapse.app.generic_worker",
@@ -69,6 +85,8 @@ def test_background_worker_subscribed_to_user_ip(self) -> None:
6985
)
7086

7187
def test_non_background_worker_not_subscribed_to_user_ip(self) -> None:
88+
from synapse.replication.tcp.redis import RedisDirectTcpReplicationClientFactory
89+
7290
# The default main process is subscribed to USER_IP and all RDATA channels.
7391
worker2 = self.make_worker_hs(
7492
"synapse.app.generic_worker",

0 commit comments

Comments
 (0)