dp-zp-agent/conftest.py
2026-11-15 03:36:33 +01:00

30 lines
1.4 KiB
Python

"""Shared test defaults: heavy optional models stay off unless a test enables them.
Lemmatization (Stanza) and the cross-encoder reranker change retrieval order;
regression tests must not depend on locally downloaded models. Dedicated tests
enable them with stand-ins.
"""
import os
os.environ.setdefault("RETRIEVAL_LEMMATIZER", "off")
os.environ.setdefault("RETRIEVAL_RERANKER", "off")
# No background CRZP traffic from tests that start the API.
os.environ.setdefault("CRZP_CHECK_INTERVAL_SECONDS", "0")
os.environ.setdefault("CRZP_PREPARE", "0")
# Evaluation code lives outside Git (see local/OBSAH.md). Without it, tests that
# import it at module level are skipped at collection instead of failing.
import importlib.util
import pathlib
import re
_EVAL_IMPORT = re.compile(r"^(?:from|import) tools\.(?:evaluation|graphrag\.evaluation|rag\.evaluation)\b", re.M)
_ROOT = pathlib.Path(__file__).parent
_EVAL_MISSING = importlib.util.find_spec("tools.evaluation") is None or importlib.util.find_spec("tools.graphrag.evaluation") is None
_QUESTIONS_MISSING = not (_ROOT / "tools/knowledge/questions.json").exists()
collect_ignore = []
for _path in [*_ROOT.glob("test/test_*.py"), *_ROOT.glob("tools/*/tests/test_*.py")]:
_text = _path.read_text(encoding="utf-8")
if (_EVAL_MISSING and _EVAL_IMPORT.search(_text)) or (_QUESTIONS_MISSING and "tools/knowledge/questions.json" in _text):
collect_ignore.append(str(_path.relative_to(_ROOT)))