Skip to content

Commit

Permalink
Merge pull request #718 from iorisa/refactor/unittest
Browse files Browse the repository at this point in the history
refactor: test_redis.py
  • Loading branch information
geekan authored Jan 9, 2024
2 parents ef53049 + 360f5dc commit 2522857
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions tests/metagpt/utils/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,25 @@
@Author : mashenquan
@File : test_redis.py
"""
from unittest.mock import AsyncMock

import mock
import pytest

from metagpt.config import CONFIG
from metagpt.utils.redis import Redis


async def async_mock_from_url(*args, **kwargs):
mock_client = mock.AsyncMock()
mock_client = AsyncMock()
mock_client.set.return_value = None
mock_client.get.side_effect = [b"test", b""]
return mock_client


@pytest.mark.asyncio
@mock.patch("aioredis.from_url", return_value=async_mock_from_url())
async def test_redis(mock_from_url):
async def test_redis(mocker):
# Mock
# mock_client = mock.AsyncMock()
# mock_client.set.return_value=None
# mock_client.get.side_effect = [b'test', b'']
# mock_from_url.return_value = mock_client
mocker.patch("aioredis.from_url", return_value=async_mock_from_url())

# Prerequisites
CONFIG.REDIS_HOST = "MOCK_REDIS_HOST"
Expand Down

0 comments on commit 2522857

Please sign in to comment.