aboutsummaryrefslogtreecommitdiffstats
path: root/tests/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index e9f0f6f..01ece10 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,4 +1,6 @@
1import asyncio 1import asyncio
2import os
3import tempfile
2from unittest.mock import AsyncMock, MagicMock 4from unittest.mock import AsyncMock, MagicMock
3import pytest 5import pytest
4 6
@@ -6,6 +8,23 @@ import discord
6from discord.ext import commands 8from discord.ext import commands
7 9
8 10
11@pytest.fixture(autouse=True, scope="function")
12def setup_test_env(monkeypatch):
13 test_db = os.path.join(tempfile.gettempdir(), "test_senator.db")
14 if os.path.exists(test_db):
15 os.remove(test_db)
16 monkeypatch.setenv("SENATOR_DB_PATH", test_db)
17 reload_database()
18 yield
19 if os.path.exists(test_db):
20 os.remove(test_db)
21
22
23def reload_database():
24 import cogs.utils.database as db_module
25 db_module._initialized = False
26
27
9class MockUser: 28class MockUser:
10 def __init__(self, id=12345, name="testuser", discriminator="0001"): 29 def __init__(self, id=12345, name="testuser", discriminator="0001"):
11 self.id = id 30 self.id = id