"""Run each test file in an isolated process. Several tests install lightweight ComfyUI stubs in ``sys.modules``. Running every file in one unittest discovery process lets those stubs leak between modules, so isolation is intentional here. """ from __future__ import annotations import shutil import subprocess import sys from pathlib import Path TEST_DIR = Path(__file__).resolve().parent def main() -> int: commands = [ [sys.executable, str(path)] for path in sorted(TEST_DIR.glob("test_*.py")) ] node = shutil.which("node") if node: commands.extend( [node, str(path)] for path in sorted(TEST_DIR.glob("test_*.mjs")) ) failures = [] for command in commands: print(f"\n>>> {' '.join(command)}", flush=True) completed = subprocess.run(command, cwd=TEST_DIR.parent, check=False) if completed.returncode: failures.append((command[-1], completed.returncode)) if failures: print("\nFailed tests:") for path, returncode in failures: print(f"- {path}: exit {returncode}") return 1 print(f"\nAll {len(commands)} isolated test files passed.") return 0 if __name__ == "__main__": raise SystemExit(main())