fix: make pytest collection coexist with ComfyUI root __init__

pytest collects the repo root as a Package and imports its __init__.py
during test setup; guard the ComfyUI-only relative imports behind
__package__ so the suite can import gates.* standalone. Drop the
tests/ package marker and pin pythonpath/testpaths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-21 12:56:32 +02:00
parent d75f73af2d
commit af3e78b29d
3 changed files with 21 additions and 2 deletions
+12 -2
View File
@@ -1,7 +1,17 @@
"""ComfyUI-Datasete-Gates — custom nodes."""
from .gates.node import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
from .gates import routes # noqa: F401 (registers aiohttp routes on import)
WEB_DIRECTORY = "./web"
# ComfyUI loads this directory as a package, so __package__ is set and the
# relative imports below resolve. pytest, however, collects the repo root as a
# Package and imports this file standalone (no parent package) during test
# setup — in that case the relative imports would raise. Guard on __package__
# so the test suite can import `gates.*` without dragging in aiohttp/comfy.
if __package__:
from .gates.node import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
from .gates import routes # noqa: F401 (registers aiohttp routes on import)
else: # pragma: no cover - exercised only under pytest collection
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]