Merge pull request #718 from iorisa/refactor/unittest

refactor: test_redis.py
This commit is contained in:
geekan 2024-01-09 10:11:28 +08:00 committed by GitHub
commit 25228572d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,8 +5,8 @@
@Author : mashenquan
@File : test_redis.py
"""
from unittest.mock import AsyncMock
import mock
import pytest
from metagpt.config import CONFIG
@ -14,20 +14,16 @@ 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"