mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Tests on Python 3.11 (#1044)
* Try to use Python 3.11 * Remove `asynctest` dependency * Fixed aiofiles tests * Added changelog
This commit is contained in:
parent
c7a85de579
commit
6db3778c6f
12 changed files with 36 additions and 88 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import asyncio
|
||||
from typing import AsyncContextManager, AsyncGenerator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import aiohttp_socks
|
||||
import pytest
|
||||
|
|
@ -14,12 +15,6 @@ from aiogram.methods import Request, TelegramMethod
|
|||
from aiogram.types import UNSET, InputFile
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
try:
|
||||
from asynctest import CoroutineMock, patch
|
||||
except ImportError:
|
||||
from unittest.mock import AsyncMock as CoroutineMock # type: ignore
|
||||
from unittest.mock import patch
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
|
|
@ -106,7 +101,7 @@ class TestAiohttpSession:
|
|||
session = AiohttpSession()
|
||||
await session.create_session()
|
||||
|
||||
with patch("aiohttp.ClientSession.close", new=CoroutineMock()) as mocked_close:
|
||||
with patch("aiohttp.ClientSession.close", new=AsyncMock()) as mocked_close:
|
||||
await session.close()
|
||||
mocked_close.assert_called_once()
|
||||
|
||||
|
|
@ -184,7 +179,7 @@ class TestAiohttpSession:
|
|||
|
||||
with patch(
|
||||
"aiohttp.client.ClientSession._request",
|
||||
new_callable=CoroutineMock,
|
||||
new_callable=AsyncMock,
|
||||
side_effect=side_effect,
|
||||
):
|
||||
with pytest.raises(TelegramNetworkError):
|
||||
|
|
@ -215,9 +210,9 @@ class TestAiohttpSession:
|
|||
|
||||
with patch(
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.create_session",
|
||||
new_callable=CoroutineMock,
|
||||
new_callable=AsyncMock,
|
||||
) as mocked_create_session, patch(
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
"aiogram.client.session.aiohttp.AiohttpSession.close", new_callable=AsyncMock
|
||||
) as mocked_close:
|
||||
async with session as ctx:
|
||||
assert session == ctx
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import datetime
|
||||
import json
|
||||
from typing import AsyncContextManager, AsyncGenerator, Optional
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -25,12 +26,6 @@ from aiogram.methods import DeleteMessage, GetMe, TelegramMethod
|
|||
from aiogram.types import UNSET, User
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
try:
|
||||
from asynctest import CoroutineMock, patch
|
||||
except ImportError:
|
||||
from unittest.mock import AsyncMock as CoroutineMock # type: ignore
|
||||
from unittest.mock import patch
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
|
|
@ -227,7 +222,7 @@ class TestBaseSession:
|
|||
|
||||
with patch(
|
||||
"tests.test_api.test_client.test_session.test_base_session.CustomSession.close",
|
||||
new_callable=CoroutineMock,
|
||||
new_callable=AsyncMock,
|
||||
) as mocked_close:
|
||||
async with session as ctx:
|
||||
assert session == ctx
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue