From f6ee8ff63f2f762d7a60e6190187be135b583bb1 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 25 Sep 2021 03:49:46 +0200 Subject: [PATCH] Move mbot creation into fixture --- test/conftest.py | 8 ++++++++ test/test_bot.py | 10 ++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 1fa415c..78725ff 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -9,6 +9,8 @@ from pytest_mock import MockerFixture SRC_PATH = str(Path(__file__).parent / '..' / 'src') sys.path.insert(0, SRC_PATH) +from bot import Music + @pytest.fixture def bot(mocker: MockerFixture): @@ -17,6 +19,12 @@ def bot(mocker: MockerFixture): yield bot_mock +@pytest.fixture +def mbot(bot): + mbot_mock = Music(bot) + yield mbot_mock + + @pytest.fixture def ctx(mocker: MockerFixture): yield mocker.patch('discord.ext.commands.Context', autospec=True) diff --git a/test/test_bot.py b/test/test_bot.py index 230c8a7..d04596c 100644 --- a/test/test_bot.py +++ b/test/test_bot.py @@ -4,13 +4,9 @@ from unittest.mock import Mock, AsyncMock, patch import pytest from discord.ext import commands -from bot import Music - @pytest.mark.asyncio -async def test_bot_ensure_voice(bot, ctx): - mbot = Music(bot) - +async def test_bot_ensure_voice(mbot, ctx): # Connects to voice channel of author if possible ctx.voice_client = None ctx.author.voice = AsyncMock() @@ -26,9 +22,7 @@ async def test_bot_ensure_voice(bot, ctx): @pytest.mark.asyncio -async def test_bot_play(bot, ctx): - mbot = Music(bot) - +async def test_bot_play(mbot, ctx): with patch.object(mbot, '_ytdl') as ytdl: with patch('discord.FFmpegPCMAudio') as ffmpeg_pcm_audio: ctx.voice_client.is_playing.return_value = False