forked from CSC510-Group-25/ClassMateBot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
conftest.py
52 lines (42 loc) · 1.4 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import sys
import discord.ext.test as dpytest
import pytest_asyncio
from discord import Intents
from discord.ext.commands import Bot
from setuptools import glob
from os.path import dirname as d
from os.path import abspath, join
import db
db.TESTING_MODE = True
intents = Intents.all()
root_dir = d(d(abspath("test/test_bot.py")))
sys.path.append(root_dir)
# Default parameters for the simulated dpytest bot. Loads the bot with commands from the /cogs directory
# Ran everytime pytest is called
@pytest_asyncio.fixture
async def bot(event_loop):
bot = Bot(intents=intents, command_prefix="$", loop=event_loop)
dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(dir)
os.chdir("cogs")
for filename in os.listdir(os.getcwd()):
if filename.endswith(".py"):
await bot.load_extension(f"cogs.{filename[:-3]}")
await bot.load_extension("jishaku")
await bot._async_setup_hook()
dpytest.configure(bot)
return bot
# Cleans up leftover files generated through dpytest
def pytest_sessionfinish():
# Clean up attachment files
files = glob.glob("./dpytest_*.dat")
for path in files:
try:
os.remove(path)
except Exception as e:
print(f"Error while deleting file {path}: {e}")
print("\npySession closed successfully")
# rollback all db modifications made
db.CONN.rollback()
# Copyright (c) 2021 War-Keeper