conftest.py python
36 lines 1.2 KB
Raw
sha256:cf6265cea8c21d9228d90dec13ef6ec2dab5103d466db9cc4590681832de4bf8 docs(KD-STAGING): sync governance after KD-6b DONE Human 13 days ago
1 """Pytest configuration and shared fixtures for the muse test suite.
2
3 All fixtures defined here are automatically available to every test module
4 in the ``tests/`` directory without explicit import.
5 """
6
7 from __future__ import annotations
8
9 import os
10 from typing import Generator
11
12 import pytest
13
14
15 @pytest.fixture(autouse=True)
16 def _restore_cwd() -> Generator[None, None, None]:
17 """Restore the working directory and MUSE_REPO_ROOT after every test.
18
19 Several tests call ``os.chdir()`` to enter a temporary repository, and
20 some directly mutate ``os.environ["MUSE_REPO_ROOT"]`` without cleanup.
21 Without this fixture those side-effects leak into subsequent tests,
22 causing ``find_repo_root()`` to resolve against a stale path and
23 producing spurious failures across the entire suite.
24
25 Note: module-scoped fixtures that set these values run *before* this
26 function-scoped fixture captures them, so they must manage their own
27 cleanup (yield + restore in the fixture body).
28 """
29 original_cwd = os.getcwd()
30 original_root = os.environ.get("MUSE_REPO_ROOT")
31 yield
32 os.chdir(original_cwd)
33 if original_root is None:
34 os.environ.pop("MUSE_REPO_ROOT", None)
35 else:
36 os.environ["MUSE_REPO_ROOT"] = original_root
File History 1 commit
sha256:cf6265cea8c21d9228d90dec13ef6ec2dab5103d466db9cc4590681832de4bf8 docs(KD-STAGING): sync governance after KD-6b DONE Human 13 days ago