diff options
Diffstat (limited to 'tests/conftest.py')
| -rw-r--r-- | tests/conftest.py | 19 |
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 @@ | |||
| 1 | import asyncio | 1 | import asyncio |
| 2 | import os | ||
| 3 | import tempfile | ||
| 2 | from unittest.mock import AsyncMock, MagicMock | 4 | from unittest.mock import AsyncMock, MagicMock |
| 3 | import pytest | 5 | import pytest |
| 4 | 6 | ||
| @@ -6,6 +8,23 @@ import discord | |||
| 6 | from discord.ext import commands | 8 | from discord.ext import commands |
| 7 | 9 | ||
| 8 | 10 | ||
| 11 | @pytest.fixture(autouse=True, scope="function") | ||
| 12 | def 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 | |||
| 23 | def reload_database(): | ||
| 24 | import cogs.utils.database as db_module | ||
| 25 | db_module._initialized = False | ||
| 26 | |||
| 27 | |||
| 9 | class MockUser: | 28 | class 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 |
