from pathlib import Path import pytest @pytest.fixture def get_test_file_path(): """ 获取测试数据文件的绝对路径 Args: relative_path (str): 相对于 tests/data/ 的文件路径 Returns: Path: 绝对路径对象 """ def _get_path(relative_path): return (Path(__file__).parent / "data" / relative_path).resolve() return _get_path @pytest.fixture def get_data_file_path(): """ 获取项目 data/ 目录下数据文件的绝对路径 Args: relative_path (str): 相对于项目根 data/ 的文件路径,如 "db/vocabulary.txt" Returns: Path: 绝对路径对象 """ def _get_path(relative_path): return (Path(__file__).parent.parent / "data" / relative_path).resolve() return _get_path