37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""Shared pytest fixtures."""
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
_REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
_REPO_SRC = _REPO_ROOT / "src"
|
|
if str(_REPO_SRC) not in sys.path:
|
|
sys.path.insert(0, str(_REPO_SRC))
|
|
|
|
# V3 nodes import ``comfy_api.latest`` at module load time. Resolve a
|
|
# ComfyUI checkout in priority order so test files importing the node
|
|
# module pick up ``comfy_api`` automatically:
|
|
# 1. COMFYUI_ROOT env var (CI / non-developer machines)
|
|
# 2. ../../../repo/ComfyUI relative to the repo
|
|
# (the layout used on the local dev workstation)
|
|
# 3. ../ComfyUI next to the repo root
|
|
#
|
|
# If none exist, V3-loading tests use ``pytest.importorskip("comfy_api")``
|
|
# and skip cleanly. Tests that don't need comfy (JS-asset / route-
|
|
# registration) keep working in either case.
|
|
_COMFY_CANDIDATES = [
|
|
os.environ.get("COMFYUI_ROOT"),
|
|
_REPO_ROOT.parent.parent.parent / "repo" / "ComfyUI",
|
|
_REPO_ROOT.parent / "ComfyUI",
|
|
]
|
|
for _candidate in _COMFY_CANDIDATES:
|
|
if _candidate is None:
|
|
continue
|
|
_path = Path(_candidate)
|
|
if _path.is_dir():
|
|
_candidate_str = str(_path)
|
|
if _candidate_str not in sys.path:
|
|
sys.path.insert(0, _candidate_str)
|
|
break
|