musicube/test/conftest.py

41 lines
876 B
Python

import asyncio
import sys
from pathlib import Path
from unittest.mock import Mock
import pytest
from pytest_mock import MockerFixture
# Add source to PATH such that imports within src modules are properly resolved.
SRC_PATH = str(Path(__file__).parent / '..' / 'src')
sys.path.insert(0, SRC_PATH)
from bot import Music
@pytest.fixture
def bot(mocker: MockerFixture):
bot_mock = mocker.patch('discord.ext.commands.Bot', autospec=True)
bot_mock.loop = Mock()
yield bot_mock
@pytest.fixture
def mbot(bot):
mbot_mock = Music(bot)
yield mbot_mock
mbot_mock.cog_unload()
@pytest.fixture
def ctx(mocker: MockerFixture):
yield mocker.patch('discord.ext.commands.Context', autospec=True)
@pytest.fixture
def event_loop():
loop = asyncio.get_event_loop()
yield loop
pending = asyncio.all_tasks(loop=loop)
asyncio.ensure_future(asyncio.gather(*pending))