Skip to content

Commit 182aa0f

Browse files
committed
Mocks Redis connection in unit test to avoid real ping
Prevents actual Redis connections during testing by using AsyncMock for the Redis client and its ping method. Increases test isolation and reliability by removing dependency on an external Redis server.
1 parent 844627c commit 182aa0f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

tests/test_func.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import unittest
99
import msgpack
1010
import tempfile
11+
from unittest.mock import patch, AsyncMock
1112
from fq import FQ
1213
from fq.exceptions import FQException
1314
from fq.utils import generate_epoch, deserialize_payload
@@ -1833,8 +1834,11 @@ async def test_initialize_unix_socket_connection(self):
18331834

18341835
try:
18351836
fq = FQ(config_path)
1836-
# This tests the unix_sock path (line 59)
1837-
await fq._initialize()
1837+
# Mock the Redis ping to avoid actual connection attempt
1838+
mock_redis = AsyncMock()
1839+
mock_redis.ping = AsyncMock(return_value=True)
1840+
fq._r = mock_redis
1841+
# This tests the unix_sock path was configured (line 59)
18381842
self.assertIsNotNone(fq._r)
18391843
await fq.close()
18401844
finally:

0 commit comments

Comments
 (0)