2025-10-11 01:07:45 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2025-09-20 22:53:37 +08:00
|
|
|
import os
|
2026-03-21 00:03:33 +08:00
|
|
|
import sys
|
2026-03-30 15:24:47 +08:00
|
|
|
from pathlib import Path
|
2026-03-21 00:03:33 +08:00
|
|
|
|
2025-09-20 22:53:37 +08:00
|
|
|
import pytest
|
2026-01-21 15:15:52 +08:00
|
|
|
|
2026-03-30 15:24:47 +08:00
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
|
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
2026-01-21 15:15:52 +08:00
|
|
|
|
2026-03-30 15:24:47 +08:00
|
|
|
# Avoid package-level knowledge graph initialization during pytest collection.
|
|
|
|
|
os.environ.setdefault("YUXI_SKIP_APP_INIT", "1")
|
2025-10-11 01:07:45 +08:00
|
|
|
|
2026-06-13 20:33:40 +08:00
|
|
|
# Pre-populate sys.modules for packages with heavy __init__.py imports
|
|
|
|
|
# (sklearn/scipy/numpy chain) so that submodules can be imported directly.
|
|
|
|
|
import types
|
|
|
|
|
|
|
|
|
|
_PACKAGE_DIR = PROJECT_ROOT / "package"
|
|
|
|
|
for _mod_name in ("yuxi.knowledge", "yuxi.knowledge.parser"):
|
|
|
|
|
if _mod_name not in sys.modules:
|
|
|
|
|
_m = types.ModuleType(_mod_name)
|
|
|
|
|
_m.__path__ = [str(_PACKAGE_DIR / _mod_name.replace(".", os.sep))]
|
|
|
|
|
_m.__package__ = _mod_name
|
|
|
|
|
sys.modules[_mod_name] = _m
|
|
|
|
|
|
2025-10-11 01:07:45 +08:00
|
|
|
|
|
|
|
|
def pytest_configure(config: pytest.Config) -> None:
|
2026-03-30 15:24:47 +08:00
|
|
|
"""Register shared markers without binding every test to a live environment."""
|
|
|
|
|
config.addinivalue_line("markers", "unit: marks tests that run without live services")
|
2025-09-20 22:53:37 +08:00
|
|
|
config.addinivalue_line("markers", "auth: marks tests that require authentication")
|
2025-10-11 01:07:45 +08:00
|
|
|
config.addinivalue_line("markers", "integration: marks tests that hit the live API service")
|
2026-03-30 15:24:47 +08:00
|
|
|
config.addinivalue_line("markers", "e2e: marks tests that exercise an end-to-end workflow")
|
|
|
|
|
config.addinivalue_line("markers", "slow: marks tests as slow")
|
2025-09-20 22:53:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
pytest_plugins = ["pytest_asyncio"]
|