Files
Reithan-negative_rejection_…/tests/conftest.py
T
Reithan ee6dc40393 Add git hooks and development infrastructure (#32)
## Summary

Establishes a complete development infrastructure for the project with
automated quality checks, testing, and contributor guidelines.

- Add pre-commit hooks for automated linting and quality checks
- Configure ruff for code linting and formatting (120 char line length,
Python 3.10+)
- Set up pytest with mocked torch/gradio dependencies for CI/CD
compatibility
- Create comprehensive CONTRIBUTING.md with setup instructions and
workflow guidance
- Add uv.lock for reproducible dependency resolution
- Replace trivial tests with functional interface tests

## Key Components

### Git Hooks (.pre-commit-config.yaml)
- Pre-commit: ruff linting/formatting, trailing whitespace, YAML
validation, prevents direct commits to main
- Pre-push: runs pytest test suite, prevents direct pushes to main

### Testing (tests/)
- Functional tests for ComfyUI node and WebUI script interfaces
- Mock torch, gradio, and WebUI modules via conftest.py (no heavy
dependencies in dev env)
- Tests verify API contracts without requiring full ComfyUI/WebUI
runtime

### Documentation (CONTRIBUTING.md)
- Development setup with uv package manager
- Git workflow and branch protection guidelines
- Linting, testing, and pre-commit hook usage
- Code style guidelines and commit message conventions

## Test Plan

- [x] Pre-commit hooks run on commit (linting, formatting, checks)
- [x] Pre-push hooks run pytest successfully
- [x] All tests pass in isolated venv
- [x] CONTRIBUTING.md instructions verified
- [x] No IDE diagnostics or issues
2026-05-15 16:08:45 -07:00

31 lines
1.1 KiB
Python

"""Pytest configuration - mock torch and gradio since they're provided by ComfyUI/WebUI at runtime."""
import sys
from unittest.mock import MagicMock
# Create mock base class for WebUI Script
class MockScript:
"""Mock base class for WebUI scripts."""
AlwaysVisible = "AlwaysVisible" # Mock the AlwaysVisible constant
# Mock torch, gradio, and WebUI modules before any imports happen
# This allows pytest to discover and import tests without these heavy dependencies
sys.modules["torch"] = MagicMock()
# Mock gradio with return_value configured for common patterns
mock_gradio = MagicMock()
mock_gradio.Accordion = MagicMock(return_value=MagicMock(__enter__=MagicMock(), __exit__=MagicMock()))
sys.modules["gradio"] = mock_gradio
# Mock WebUI modules with proper base class
mock_modules = MagicMock()
mock_modules.scripts = MagicMock()
mock_modules.scripts.Script = MockScript
mock_modules.script_callbacks = MagicMock()
sys.modules["modules"] = mock_modules
sys.modules["modules.scripts"] = mock_modules.scripts
sys.modules["modules.script_callbacks"] = mock_modules.script_callbacks