Редактировать conftest.py

This commit is contained in:
Markov Andrey
2026-06-30 10:34:12 +00:00
parent 1e2e18d77b
commit a11f6db9c7

69
tests/conftest.py Normal file
View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
"""
Фикстуры для тестов: моки для GigaClient, BotConfig, и других зависимостей.
Автоматически очищает глобальные кэши (intent, expand) перед каждым тестом.
"""
import pytest
from unittest.mock import AsyncMock, MagicMock
from core.services.giga_client import GigaClient
from core.utils.config_loader import BotConfig
@pytest.fixture(autouse=True)
def clear_caches():
"""
Автоматически очищает глобальные кэши перед каждым тестом,
чтобы избежать влияния между тестами.
"""
from core.functions.intent_classify import _intent_cache
from core.functions.expand_query import _expand_cache
_intent_cache.clear()
_expand_cache.clear()
@pytest.fixture
def mock_giga():
"""Создаёт мок GigaClient с подменой метода chat()."""
giga = AsyncMock(spec=GigaClient)
# По умолчанию chat возвращает строку
giga.chat = AsyncMock(return_value="GENERAL")
return giga
@pytest.fixture
def mock_bot_config():
"""Создаёт мок BotConfig с минимальными настройками."""
config = MagicMock(spec=BotConfig)
# Подсекции
config.intent = {"temperature": 0.1}
config.expand = {"temperature": 0.1}
config.metrics = {"temperature": 0.1}
config.summary = {"temperature": 0.1, "max_chars": 8000}
config.consistency = {"temperature": 0.1, "max_fragments": 5}
config.critique = {"temperature": 0.1}
config.rerank = {"temperature": 0.1, "min_length": 5000}
config.spellcheck = {"temperature": 0.1}
return config
@pytest.fixture
def sample_prompt_intent():
"""Возвращает содержимое intent_classify.txt для тестов."""
return """
Ты — классификатор намерений...
КОДЫ НАМЕРЕНИЙ:
- `FACT` ...
ВОПРОС: {query}
"""
@pytest.fixture
def sample_prompt_expand():
"""Возвращает содержимое expand.txt для тестов."""
return """
Ты — эксперт по информационному поиску...
ВОПРОС: {query}
РАСШИРЕННЫЙ ЗАПРОС:
"""