musicube/test/conftest.py

41 lines
876 B
Python
Raw Normal View History

2021-09-25 14:48:33 +00:00
import asyncio
2021-09-24 19:57:25 +00:00
import sys
from pathlib import Path
2021-09-24 21:37:46 +00:00
from unittest.mock import Mock
2021-09-24 19:57:25 +00:00
2021-09-24 21:07:32 +00:00
import pytest
from pytest_mock import MockerFixture
2021-09-24 19:57:25 +00:00
# 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)
2021-09-24 21:07:32 +00:00
2021-09-25 01:49:46 +00:00
from bot import Music
2021-09-24 21:07:32 +00:00
@pytest.fixture
def bot(mocker: MockerFixture):
2021-09-24 21:37:46 +00:00
bot_mock = mocker.patch('discord.ext.commands.Bot', autospec=True)
bot_mock.loop = Mock()
yield bot_mock
2021-09-24 21:07:32 +00:00
2021-09-25 01:49:46 +00:00
@pytest.fixture
def mbot(bot):
mbot_mock = Music(bot)
yield mbot_mock
2021-09-25 14:48:33 +00:00
mbot_mock.cog_unload()
2021-09-25 01:49:46 +00:00
2021-09-24 21:07:32 +00:00
@pytest.fixture
def ctx(mocker: MockerFixture):
yield mocker.patch('discord.ext.commands.Context', autospec=True)
2021-09-25 14:48:33 +00:00
@pytest.fixture
def event_loop():
loop = asyncio.get_event_loop()
yield loop
pending = asyncio.all_tasks(loop=loop)
asyncio.ensure_future(asyncio.gather(*pending))