Files
Gregory RichardandClaude Opus 5.5 64cd60dd5d fix: tests import the pack without ComfyUI
pytest imports the pack root while collecting, before any fixture runs, so the
comfy_api stand-in is installed when conftest loads and __init__ falls back to
an absolute import outside a package, as in WarpPipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 23:15:01 +01:00

64 lines
1.6 KiB
Python

"""Load realism.py without ComfyUI: a minimal stand-in for comfy_api.latest."""
import importlib.util
import sys
import types
from pathlib import Path
import pytest
PROJECT_ROOT = Path(__file__).resolve().parents[1]
class _Field:
def __init__(self, field_id=None, **options):
self.id = field_id
self.options = options
def _io_type():
return type("IoType", (), {"Input": type("Input", (_Field,), {}), "Output": type("Output", (_Field,), {})})
class _Schema:
def __init__(self, node_id, inputs=(), outputs=(), **kwargs):
self.node_id = node_id
self.inputs = list(inputs)
self.outputs = list(outputs)
self.options = kwargs
class _NodeOutput:
def __init__(self, *args):
self.args = args
io = types.SimpleNamespace(
ComfyNode=type("ComfyNode", (), {}),
Schema=_Schema,
NodeOutput=_NodeOutput,
Image=_io_type(),
Float=_io_type(),
Int=_io_type(),
)
# installed at import time: pytest imports the pack's __init__.py while collecting, before any fixture runs
_latest = types.ModuleType("comfy_api.latest")
_latest.ComfyExtension = type("ComfyExtension", (), {})
_latest.io = io
_comfy_api = types.ModuleType("comfy_api")
_comfy_api.__path__ = []
_comfy_api.latest = _latest
sys.modules.setdefault("comfy_api", _comfy_api)
sys.modules.setdefault("comfy_api.latest", _latest)
sys.path.insert(0, str(PROJECT_ROOT))
@pytest.fixture(scope="session")
def realism():
spec = importlib.util.spec_from_file_location("realism", PROJECT_ROOT / "realism.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module