test
This commit is contained in:
25
examples/todo_skill/tests/conftest.py
Normal file
25
examples/todo_skill/tests/conftest.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user