File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed
Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ celerybeat.pid
105105
106106# Environments
107107.env
108+ ! /tests /modmail /test.env
108109.venv
109110env /
110111venv /
Original file line number Diff line number Diff line change 1+ import os
2+ import pathlib
3+ import unittest .mock
4+
5+ import dotenv
16import 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
Original file line number Diff line number Diff line change 1+ MODMAIL_BOT_TOKEN = ' NjQzOTQ1MjY0ODY4MDk4MDQ5.342b.4inDLBILY69LOLfyi6jk420dpyjoEVsCoModM'
You can’t perform that action at this time.
0 commit comments