Files
ArticleReplaceBatch/tests/conftest.py

77 lines
1.9 KiB
Python
Raw Normal View History

2026-03-25 15:17:18 +08:00
"""
pytest配置文件
"""
import os
import sys
from pathlib import Path
import pytest
# 添加项目根目录到Python路径
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
@pytest.fixture(scope="session")
def project_root_path():
"""返回项目根目录"""
return Path(__file__).parent.parent
@pytest.fixture(scope="session")
def test_data_dir(project_root_path):
"""返回测试数据目录"""
return project_root_path / "tests" / "data"
@pytest.fixture
def mock_config():
"""提供模拟配置"""
return {
"General": {
"chrome_user_dir": "C:\\Users\\test\\AppData\\Local\\Google\\Chrome\\User Data",
"articles_path": "test_articles",
"images_path": "test_picture",
"title_file": "test_links.xlsx",
"max_threads": "1",
"min_article_length": "50",
"enable_plagiarism_detection": "false"
},
"Coze": {
"workflow_id": "test_workflow",
"access_token": "test_token",
"is_async": "false"
},
"Baidu": {
"api_key": "",
"secret_key": "",
"enable_detection": "false"
},
"ImageModify": {
"crop_percent": "0.02",
"min_rotation": "0.3",
"max_rotation": "3.0",
"min_brightness": "0.8",
"max_brightness": "1.2",
"watermark_text": "Test",
"watermark_opacity": "128",
"overlay_opacity": "30"
},
"Keywords": {
"banned_words": "test"
}
}
@pytest.fixture
def temp_dir(tmp_path):
"""提供临时目录"""
return tmp_path
@pytest.fixture(autouse=True)
def setup_test_env(monkeypatch, temp_dir):
"""自动设置测试环境"""
# 使用临时目录避免影响真实数据
monkeypatch.setenv("TESTING", "1")