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:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user