"""Pytest configuration and shared fixtures for the muse test suite. All fixtures defined here are automatically available to every test module in the ``tests/`` directory without explicit import. """ from __future__ import annotations import os from typing import Generator import pytest @pytest.fixture(autouse=True) def _restore_cwd() -> Generator[None, None, None]: """Restore the working directory and MUSE_REPO_ROOT after every test. Several tests call ``os.chdir()`` to enter a temporary repository, and some directly mutate ``os.environ["MUSE_REPO_ROOT"]`` without cleanup. Without this fixture those side-effects leak into subsequent tests, causing ``find_repo_root()`` to resolve against a stale path and producing spurious failures across the entire suite. Note: module-scoped fixtures that set these values run *before* this function-scoped fixture captures them, so they must manage their own cleanup (yield + restore in the fixture body). """ original_cwd = os.getcwd() original_root = os.environ.get("MUSE_REPO_ROOT") yield os.chdir(original_cwd) if original_root is None: os.environ.pop("MUSE_REPO_ROOT", None) else: os.environ["MUSE_REPO_ROOT"] = original_root