"""Make `presa_mano.*` importable in tests without installing the package.""" from __future__ import annotations import sys from pathlib import Path _SRC = Path(__file__).resolve().parent.parent / "src" if str(_SRC) not in sys.path: sys.path.insert(0, str(_SRC)) import pytest _CFG_PATH = Path(__file__).resolve().parent.parent / "config.yaml" @pytest.fixture(autouse=True) def _restore_config_yaml(): """Snapshot/restore config.yaml + in-memory singleton. Any test that triggers update_config() would otherwise leave the file cosmetically reformatted (compact flow-style -> block-style) AND/OR semantically mutated. This fixture keeps the working tree clean.""" if not _CFG_PATH.exists(): yield return snapshot = _CFG_PATH.read_bytes() try: yield finally: _CFG_PATH.write_bytes(snapshot) # Reset in-memory singleton so subsequent tests re-read disk try: from presa_mano import config as _cfg_mod _cfg_mod._STATE["config"] = None # type: ignore[attr-defined] except Exception: pass # if internals change, we still get the disk reset