Forget a stale namespace 'app' after a failed ComfyUI logger import

Fixes the 'cannot import name governance from app' collection error when pytest loads the root package before ComfyUI is on sys.path.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tw9fjV3UWsHHjJiAXix29B
This commit is contained in:
Claude
2026-11-05 12:03:30 +00:00
parent 430a6d5e93
commit 374cf3de29
2 changed files with 19 additions and 0 deletions
+4
View File
@@ -90,6 +90,10 @@ def _memory():
try:
import app.logger as comfy_log
except Exception: # noqa: BLE001
# Without ComfyUI on the path, `app` resolves to our own folder (a namespace package) and stays cached,
# which would later hide ComfyUI's real `app` package. Forget it.
if getattr(sys.modules.get("app"), "__file__", True) is None:
sys.modules.pop("app", None)
return None
logs = comfy_log.logs
if logs is not None and not isinstance(logs, Kept):
+15
View File
@@ -0,0 +1,15 @@
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
def test_failed_comfy_logger_import_leaves_no_stale_app_package():
"""Outside ComfyUI, `app` is our own folder; it must not stay cached and hide ComfyUI's real `app` later."""
code = (
"import sys; sys.path.insert(0, %r); import core.backend_log; "
"print('app' in sys.modules and getattr(sys.modules['app'], '__file__', 1) is None)"
) % str(ROOT)
out = subprocess.run([sys.executable, "-I", "-c", code], capture_output=True, text=True, cwd=str(ROOT))
assert out.stdout.strip().endswith("False"), out.stdout + out.stderr