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')
|
SRC_PATH = str(Path(__file__).parent / '..' / 'src')
|
||||||
sys.path.insert(0, SRC_PATH)
|
sys.path.insert(0, SRC_PATH)
|
||||||
|
|
||||||
|
from bot import Music
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def bot(mocker: MockerFixture):
|
def bot(mocker: MockerFixture):
|
||||||
|
@ -17,6 +19,12 @@ def bot(mocker: MockerFixture):
|
||||||
yield bot_mock
|
yield bot_mock
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mbot(bot):
|
||||||
|
mbot_mock = Music(bot)
|
||||||
|
yield mbot_mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def ctx(mocker: MockerFixture):
|
def ctx(mocker: MockerFixture):
|
||||||
yield mocker.patch('discord.ext.commands.Context', autospec=True)
|
yield mocker.patch('discord.ext.commands.Context', autospec=True)
|
||||||
|
|
|
@ -4,13 +4,9 @@ from unittest.mock import Mock, AsyncMock, patch
|
||||||
import pytest
|
import pytest
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from bot import Music
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bot_ensure_voice(bot, ctx):
|
async def test_bot_ensure_voice(mbot, ctx):
|
||||||
mbot = Music(bot)
|
|
||||||
|
|
||||||
# Connects to voice channel of author if possible
|
# Connects to voice channel of author if possible
|
||||||
ctx.voice_client = None
|
ctx.voice_client = None
|
||||||
ctx.author.voice = AsyncMock()
|
ctx.author.voice = AsyncMock()
|
||||||
|
@ -26,9 +22,7 @@ async def test_bot_ensure_voice(bot, ctx):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bot_play(bot, ctx):
|
async def test_bot_play(mbot, ctx):
|
||||||
mbot = Music(bot)
|
|
||||||
|
|
||||||
with patch.object(mbot, '_ytdl') as ytdl:
|
with patch.object(mbot, '_ytdl') as ytdl:
|
||||||
with patch('discord.FFmpegPCMAudio') as ffmpeg_pcm_audio:
|
with patch('discord.FFmpegPCMAudio') as ffmpeg_pcm_audio:
|
||||||
ctx.voice_client.is_playing.return_value = False
|
ctx.voice_client.is_playing.return_value = False
|
||||||
|
|
Loading…
Reference in New Issue