Move mbot creation into fixture
This commit is contained in:
parent
d96108119e
commit
f6ee8ff63f
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue