fix: clean up omnivoice import guard and __init__ error masking

Remove OmniVoice = None fallback in nodes/loader.py so missing omnivoice
gives a clear ImportError instead of a confusing AttributeError. Restore
__init__.py to clean form without the try/except that silently swallowed
real import errors. Add omnivoice mock to conftest.py and register a
pytest plugin that prevents pytest from treating the project root as a
Package node (which would try to import __init__.py outside a package
context and fail on the relative import).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-05 09:03:34 +02:00
parent 069169485d
commit 11beba1c47
4 changed files with 41 additions and 19 deletions
+26 -1
View File
@@ -1,6 +1,31 @@
import sys
import os
from pathlib import Path
from unittest.mock import MagicMock
# Ensure the project root is on sys.path so `nodes.loader` can be imported
# as a top-level package without needing to install the package.
sys.path.insert(0, os.path.dirname(__file__))
_root = os.path.dirname(__file__)
sys.path.insert(0, _root)
# Mock omnivoice so it can be imported in tests without being installed
sys.modules.setdefault("omnivoice", MagicMock())
# Prevent pytest from treating the project root as a Python Package node.
# The root __init__.py is a ComfyUI extension entrypoint that uses relative
# imports and cannot be imported by pytest without a proper package context.
# Overriding pytest_collect_directory stops pytest from creating a Package
# node (and calling Package.setup() which imports __init__.py) for the root.
class _RootDirPlugin:
"""Registered as a plugin so it intercepts hooks before conftest scope limits."""
def pytest_collect_directory(self, path, parent):
from _pytest.main import Dir
if Path(path) == Path(_root):
# Return a plain Dir node instead of a Package node for the root,
# so pytest skips importing __init__.py during Package.setup().
return Dir.from_parent(parent, path=Path(path))
def pytest_configure(config):
config.pluginmanager.register(_RootDirPlugin(), "_root_dir_plugin")