"""根级 conftest — 全局 fixture:配置加载、日志、测试数据清理。 自动应用于 tests/ 下所有测试模块。 """ from pathlib import Path import pytest # 将 tests/ 目录加入 Python path,确保 `from tests.xxx import yyy` 可用 import sys sys.path.insert(0, str(Path(__file__).parent.parent)) @pytest.fixture(scope="session") def config(): """全局配置 fixture(session 级别,只加载一次)。""" from tests.config.test_config import load_config return load_config() @pytest.fixture(scope="function") def logger(request): """每个测试函数一个 logger,自动以模块名命名。""" from tests.utils.logger import get_logger module_name = request.module.__name__.replace("tests.", "") return get_logger(module_name)