Skip to content

Commit dbdb3a1

Browse files
feat: use a specific testing environment
1 parent 30ded20 commit dbdb3a1

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ celerybeat.pid
104104
*.sage.py
105105

106106
# Environments
107+
!test.env
107108
.env
108109
.venv
109110
env/

tests/modmail/conftest.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import os
2+
import pathlib
3+
import unittest.mock
4+
5+
import dotenv
16
import pytest
27

38

@@ -12,3 +17,23 @@ def patch_embeds():
1217
import modmail.utils.embeds
1318

1419
modmail.utils.embeds.patch_embed()
20+
21+
22+
def _get_env():
23+
return pathlib.Path(__file__).parent / "test.env"
24+
25+
26+
def pytest_configure():
27+
"""Check that the test specific env file exists, and cancel the run if it does not exist."""
28+
env = _get_env()
29+
if not env.is_file():
30+
pytest.exit(f"Testing specific {env} does not exist. Cancelling test run.", 2)
31+
32+
33+
@pytest.fixture(autouse=True, scope="package")
34+
def standardize_environment():
35+
"""Clear environment variables except for the test.env file."""
36+
env = _get_env()
37+
with unittest.mock.patch.dict(os.environ, clear=True):
38+
dotenv.load_dotenv(env)
39+
yield

tests/modmail/test.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MODMAIL_BOT_TOKEN='NjQzOTQ1MjY0ODY4MDk4MDQ5.342b.4inDLBILY69LOLfyi6jk420dpyjoEVsCoModM'

0 commit comments

Comments
 (0)