From af0c7663eca52da5d6ae03b15f377f091b333760 Mon Sep 17 00:00:00 2001 From: Guido Petretto Date: Fri, 17 Nov 2023 15:46:47 +0100 Subject: [PATCH] Move `_clear_tracked_cache` fixture (#307) * move _clear_tracked_cache fixture to specific test files * fix lint --- tests/vasp/conftest.py | 10 ---------- tests/vasp/test_handlers.py | 10 ++++++++++ tests/vasp/test_io.py | 12 ++++++++++++ tests/vasp/test_validators.py | 12 ++++++++++++ 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/tests/vasp/conftest.py b/tests/vasp/conftest.py index bf67d0e7..f8728305 100644 --- a/tests/vasp/conftest.py +++ b/tests/vasp/conftest.py @@ -12,13 +12,3 @@ def _patch_get_potential_energy(monkeypatch): Monkeypatch the multiprocessing.cpu_count() function to always return 64 """ monkeypatch.setattr(multiprocessing, "cpu_count", lambda *args, **kwargs: 64) - - -@pytest.fixture(autouse=True) -def _clear_tracked_cache(): - """ - Clear the cache of the stored functions between the tests. - """ - from custodian.utils import tracked_lru_cache - - tracked_lru_cache.tracked_cache_clear() diff --git a/tests/vasp/test_handlers.py b/tests/vasp/test_handlers.py index ee6c5362..78930d85 100644 --- a/tests/vasp/test_handlers.py +++ b/tests/vasp/test_handlers.py @@ -39,6 +39,16 @@ os.environ.setdefault("PMG_VASP_PSP_DIR", TEST_FILES) +@pytest.fixture(autouse=True) +def _clear_tracked_cache(): + """ + Clear the cache of the stored functions between the tests. + """ + from custodian.utils import tracked_lru_cache + + tracked_lru_cache.tracked_cache_clear() + + def copy_tmp_files(tmp_path: str, *file_paths: str) -> None: for file_path in file_paths: src_path = f"{TEST_FILES}/{file_path}" diff --git a/tests/vasp/test_io.py b/tests/vasp/test_io.py index 1f85a756..d26dd4bf 100644 --- a/tests/vasp/test_io.py +++ b/tests/vasp/test_io.py @@ -1,8 +1,20 @@ +import pytest + from custodian import TEST_FILES from custodian.utils import tracked_lru_cache from custodian.vasp.io import load_outcar, load_vasprun +@pytest.fixture(autouse=True) +def _clear_tracked_cache(): + """ + Clear the cache of the stored functions between the tests. + """ + from custodian.utils import tracked_lru_cache + + tracked_lru_cache.tracked_cache_clear() + + class TestIO: def test_load_outcar(self): outcar = load_outcar(f"{TEST_FILES}/large_sigma/OUTCAR") diff --git a/tests/vasp/test_validators.py b/tests/vasp/test_validators.py index b9248d25..05e58d9c 100644 --- a/tests/vasp/test_validators.py +++ b/tests/vasp/test_validators.py @@ -1,10 +1,22 @@ import os import shutil +import pytest + from custodian import TEST_FILES from custodian.vasp.validators import VaspAECCARValidator, VaspFilesValidator, VaspNpTMDValidator, VasprunXMLValidator +@pytest.fixture(autouse=True) +def _clear_tracked_cache(): + """ + Clear the cache of the stored functions between the tests. + """ + from custodian.utils import tracked_lru_cache + + tracked_lru_cache.tracked_cache_clear() + + class TestVasprunXMLValidator: def test_check_and_correct(self): os.chdir(f"{TEST_FILES}/bad_vasprun")