From af3e78b29d9c35dd95798d34487c62e76d55edfa Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Sun, 21 Jun 2026 12:56:32 +0200 Subject: [PATCH] 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 --- __init__.py | 14 ++++++++++++-- pyproject.toml | 9 +++++++++ tests/__init__.py | 0 3 files changed, 21 insertions(+), 2 deletions(-) delete mode 100644 tests/__init__.py diff --git a/__init__.py b/__init__.py index 61aa0a0..6ae87c4 100644 --- a/__init__.py +++ b/__init__.py @@ -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"] diff --git a/pyproject.toml b/pyproject.toml index d9cfe45..adeba72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,3 +7,12 @@ requires-python = ">=3.10" [tool.comfy] PublisherId = "ethanfel" DisplayName = "ComfyUI Datasete Gates" + +[tool.pytest.ini_options] +# The repo-root __init__.py is required by ComfyUI but breaks pytest's default +# "prepend" collection if tests/ is a package (pytest walks up the __init__.py +# chain and tries to import the root package, whose relative imports fail +# outside ComfyUI). Keeping tests/ a non-package dir avoids that; pythonpath +# makes `gates` importable from the repo root. +pythonpath = ["."] +testpaths = ["tests"] diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000