Skip to content

Commit

Permalink
isolate test_load_settings() from outer env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 21, 2022
1 parent f458a15 commit 345534a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pymatgen/core/tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from pathlib import Path

from pytest import MonkeyPatch

from pymatgen.core import _load_pmg_settings

__author__ = "Janosh Riebesell"
__date__ = "2022-10-21"
__email__ = "janosh@lbl.gov"


def test_load_settings(tmp_path: Path, monkeypatch) -> None:
"""Test that the settings file can be loaded."""
def test_load_settings(tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
"""Test .pmgrc.yaml file is loaded correctly and env vars take precedence."""
monkeypatch.setattr("os.environ", {}) # reset outer env vars

settings_file = tmp_path / ".pmgrc.yaml"
monkeypatch.setattr("pymatgen.core.SETTINGS_FILE", settings_file)

Expand All @@ -26,8 +30,8 @@ def test_load_settings(tmp_path: Path, monkeypatch) -> None:
assert _load_pmg_settings() == {"PMG_MAPI_KEY": "FOOBAR"}

# env vars should override .pmgrc.yaml
with monkeypatch.context() as m:
m.setenv("PMG_MAPI_KEY", "BAZ")
with monkeypatch.context() as ctx:
ctx.setenv("PMG_MAPI_KEY", "BAZ")
assert _load_pmg_settings() == {"PMG_MAPI_KEY": "BAZ"}

# should return empty dict if file is invalid
Expand Down

0 comments on commit 345534a

Please sign in to comment.