mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-15 20:02:22 +00:00
Fixed ResourceWarnings in tests (#1366)
* #1320 Update pytest configuration and tests cleanup This commit modifies the pytest's configuration file, `pyproject.toml`, to remove filterwarnings settings. It also makes changes in various test files; the Redis isolation test is now using the provided `redis_storage` fixture instead of setting up its own connection, pytest.mark.filterwarnings is no longer used in `test_isolation.py` and `test_aiohttp_session.py` properly closes off sessions. * Added changelog * Fixed coverage for the RedisEventIsolation
This commit is contained in:
parent
9a2a72fe97
commit
3ad5ed6bc2
5 changed files with 46 additions and 20 deletions
|
|
@ -1,6 +1,10 @@
|
|||
from unittest import mock
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.fsm.storage.base import BaseEventIsolation, StorageKey
|
||||
from aiogram.fsm.storage.redis import RedisEventIsolation
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
@ -18,7 +22,6 @@ def create_storage_key(bot: MockedBot):
|
|||
],
|
||||
)
|
||||
class TestIsolations:
|
||||
@pytest.mark.filterwarnings("ignore::ResourceWarning")
|
||||
async def test_lock(
|
||||
self,
|
||||
isolation: BaseEventIsolation,
|
||||
|
|
@ -26,3 +29,35 @@ class TestIsolations:
|
|||
):
|
||||
async with isolation.lock(key=storage_key):
|
||||
assert True, "Are you kidding me?"
|
||||
|
||||
|
||||
class TestRedisEventIsolation:
|
||||
def test_init_without_key_builder(self):
|
||||
redis = AsyncMock()
|
||||
isolation = RedisEventIsolation(redis=redis)
|
||||
assert isolation.redis is redis
|
||||
|
||||
assert isolation.key_builder is not None
|
||||
|
||||
def test_init_with_key_builder(self):
|
||||
redis = AsyncMock()
|
||||
key_builder = AsyncMock()
|
||||
isolation = RedisEventIsolation(redis=redis, key_builder=key_builder)
|
||||
assert isolation.redis is redis
|
||||
assert isolation.key_builder is key_builder
|
||||
|
||||
def test_create_from_url(self):
|
||||
with patch("redis.asyncio.connection.ConnectionPool.from_url") as pool:
|
||||
isolation = RedisEventIsolation.from_url("redis://localhost:6379/0")
|
||||
assert isinstance(isolation, RedisEventIsolation)
|
||||
assert isolation.redis is not None
|
||||
assert isolation.key_builder is not None
|
||||
|
||||
assert pool.called_once_with("redis://localhost:6379/0")
|
||||
|
||||
async def test_close(self):
|
||||
isolation = RedisEventIsolation(redis=AsyncMock())
|
||||
await isolation.close()
|
||||
|
||||
# close is not called because connection should be closed from the storage
|
||||
# assert isolation.redis.close.called_once()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue