Skip to content

Commit

Permalink
debug: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
onerandomusername committed Nov 21, 2021
1 parent 3b6e345 commit c17131b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions tests/modmail/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import dotenv
import pytest

_ORIG_ENVIRON = None


def pytest_report_header(config) -> str:
"""Pytest headers."""
Expand All @@ -25,20 +27,16 @@ def _get_env():


def pytest_configure():
"""Check that the test specific env file exists, and cancel the run if it does not exist."""
"""Load the test specific environment file, exit if it does not exist."""
env = _get_env()
if not env.is_file():
pytest.exit(f"Testing specific {env} does not exist. Cancelling test run.", 2)
os.environ.clear()
dotenv.load_dotenv(_get_env(), override=True)


@pytest.fixture(autouse=True, scope="package")
def standardize_environment():
"""Clear environment variables except for the test.env file."""
env = _get_env()
with unittest.mock.patch.dict(os.environ, clear=True):

yield


os.environ = dict()
dotenv.load_dotenv(_get_env())
def pytest_unconfigure():
"""Reset os.environ to the original environment before the run."""
if _ORIG_ENVIRON is not None:
os.environ.clear()
os.environ.update(**_ORIG_ENVIRON)

0 comments on commit c17131b

Please sign in to comment.