From c7bb528cd9ac6d990cd6e126091385873454f9d9 Mon Sep 17 00:00:00 2001 From: Oleg A Date: Mon, 10 Jan 2022 11:29:42 +0300 Subject: [PATCH] chore: mv bot fixture --- tests/conftest.py | 16 ++++++++++++++++ tests/test_bot.py | 8 -------- tests/test_dispatcher.py | 8 -------- tests/test_message.py | 10 +--------- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b56c7b77..455f8b0d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,12 @@ +import asyncio + import aioredis import pytest from _pytest.config import UsageError +from aiogram import Bot +from . import TOKEN + try: import aioredis.util except ImportError: @@ -72,3 +77,14 @@ def redis_options(request): raise UsageError(f"Invalid redis URI {redis_uri!r}: {e}") raise UsageError("Unsupported aioredis version") + + +@pytest.fixture(name='bot') +async def bot_fixture(): + """Bot fixture.""" + bot = Bot(TOKEN) + yield bot + session = await bot.get_session() + if session and not session.closed: + await session.close() + await asyncio.sleep(0.2) diff --git a/tests/test_bot.py b/tests/test_bot.py index b2da7952..eea20b44 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -6,14 +6,6 @@ from . import FakeTelegram, TOKEN, BOT_ID pytestmark = pytest.mark.asyncio -@pytest.fixture(name='bot') -async def bot_fixture(): - """ Bot fixture """ - _bot = Bot(TOKEN, parse_mode=types.ParseMode.MARKDOWN_V2) - yield _bot - await _bot.close() - - async def test_get_me(bot: Bot): """ getMe method test """ from .types.dataset import USER diff --git a/tests/test_dispatcher.py b/tests/test_dispatcher.py index 81ae565c..e38d7c4a 100644 --- a/tests/test_dispatcher.py +++ b/tests/test_dispatcher.py @@ -5,14 +5,6 @@ from aiogram import Dispatcher, Bot pytestmark = pytest.mark.asyncio -@pytest.fixture(name='bot') -async def bot_fixture(): - """ Bot fixture """ - _bot = Bot(token='123456789:AABBCCDDEEFFaabbccddeeff-1234567890') - yield _bot - await _bot.close() - - class TestDispatcherInit: async def test_successful_init(self, bot): """ diff --git a/tests/test_message.py b/tests/test_message.py index 6fca789f..bc53dfbc 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -8,16 +8,8 @@ from . import FakeTelegram, TOKEN pytestmark = pytest.mark.asyncio -@pytest.fixture(name='bot') -async def bot_fixture(): - """ Bot fixture """ - _bot = Bot(TOKEN, parse_mode=types.ParseMode.HTML) - yield _bot - await _bot.close() - - @pytest.fixture() -async def message(bot): +async def message(bot: Bot): """ Message fixture :param bot: Telegram bot fixture