Files
add-todo-all/examples/todo_skill/tests/conftest.py
2026-09-09 10:29:02 +08:00

26 lines
818 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""pytest 全局 fixture:把 ``scripts/`` 注入 sys.path 并隔离数据目录。"""
from __future__ import annotations
import os
import sys
import tempfile
import pytest
_SCRIPTS_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "scripts")
if _SCRIPTS_DIR not in sys.path:
sys.path.insert(0, _SCRIPTS_DIR)
@pytest.fixture
def isolated_env(tmp_path, monkeypatch):
"""隔离的数据根目录,避免污染本机真实数据。"""
data_root = tmp_path / "data_root"
data_root.mkdir()
monkeypatch.setenv("JIANGCHANG_DATA_ROOT", str(data_root))
monkeypatch.setenv("JIANGCHANG_USER_ID", "test_user")
# 重置 config mock 的缓存,让下一次 get 重新读 env
from jiangchang_skill_core import config
config.reset_cache()
return data_root