conftest.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """Pytest configuration for the comfyui skill test suite.
  2. Adds `scripts/` to sys.path so tests can `from _common import ...`, and
  3. provides a few common fixtures.
  4. """
  5. from __future__ import annotations
  6. import json
  7. import os
  8. import sys
  9. from pathlib import Path
  10. import pytest
  11. ROOT = Path(__file__).resolve().parent.parent
  12. SCRIPTS = ROOT / "scripts"
  13. WORKFLOWS = ROOT / "workflows"
  14. sys.path.insert(0, str(SCRIPTS))
  15. @pytest.fixture
  16. def sd15_workflow() -> dict:
  17. return json.loads((WORKFLOWS / "sd15_txt2img.json").read_text(encoding="utf-8"))
  18. @pytest.fixture
  19. def flux_workflow() -> dict:
  20. return json.loads((WORKFLOWS / "flux_dev_txt2img.json").read_text(encoding="utf-8"))
  21. @pytest.fixture
  22. def video_workflow() -> dict:
  23. return json.loads((WORKFLOWS / "wan_video_t2v.json").read_text(encoding="utf-8"))
  24. @pytest.fixture
  25. def workflows_dir() -> Path:
  26. return WORKFLOWS
  27. @pytest.fixture
  28. def scripts_dir() -> Path:
  29. return SCRIPTS
  30. @pytest.fixture
  31. def cloud_key() -> str | None:
  32. """Cloud API key if set, otherwise None.
  33. Tests that need cloud connectivity should skip when this is None.
  34. """
  35. return os.environ.get("COMFY_CLOUD_API_KEY")
  36. def pytest_collection_modifyitems(config, items):
  37. """Auto-skip cloud tests when no API key is set."""
  38. if os.environ.get("COMFY_CLOUD_API_KEY"):
  39. return
  40. skip_cloud = pytest.mark.skip(reason="Set COMFY_CLOUD_API_KEY to run cloud tests")
  41. for item in items:
  42. if "cloud" in item.keywords:
  43. item.add_marker(skip_cloud)