Skip to content

Commit 534af30

Browse files
committed
PymatgenTest add @pytest.fixture(autouse=True)
def _tmp_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: make all tests run a in a temporary directory accessible via self.tmp_path
1 parent 7a54a3e commit 534af30

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pymatgen/util/testing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import unittest
1414
from pathlib import Path
1515

16+
import pytest
1617
from monty.json import MontyDecoder, MSONable
1718
from monty.serialization import loadfn
1819
from numpy.testing import assert_allclose
@@ -44,6 +45,12 @@ class PymatgenTest(unittest.TestCase):
4445
for fn in STRUCTURES_DIR.iterdir():
4546
TEST_STRUCTURES[fn.name.rsplit(".", 1)[0]] = loadfn(str(fn))
4647

48+
@pytest.fixture(autouse=True) # make all tests run a in a temporary directory accessible via self.tmp_path
49+
def _tmp_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
50+
# https://pytest.org/en/latest/how-to/unittest.html#using-autouse-fixtures-and-accessing-other-fixtures
51+
monkeypatch.chdir(tmp_path) # change to pytest-provided temporary directory
52+
self.tmp_path = tmp_path
53+
4754
@classmethod
4855
def get_structure(cls, name: str) -> Structure:
4956
"""

0 commit comments

Comments
 (0)