mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-16 18:02:58 +08:00
Add comprehensive pip dependency conflict resolution framework as draft implementation. This is self-contained and does not affect existing ComfyUI Manager functionality. Key components: - pip_util.py with PipBatch class for policy-driven package management - Lazy-loaded policy system supporting base + user overrides - Multi-stage policy execution (uninstall → apply_first_match → apply_all_matches → restore) - Conditional policies based on platform, installed packages, and ComfyUI version - Comprehensive test suite covering edge cases, workflows, and platform scenarios - Design and implementation documentation Policy capabilities (draft): - Package replacement (e.g., PIL → Pillow, opencv-python → opencv-contrib-python) - Version pinning to prevent dependency conflicts - Dependency protection during installations - Platform-specific handling (Linux/Windows, GPU detection) - Pre-removal and post-restoration workflows Testing infrastructure: - Pytest-based test suite with isolated environments - Dependency analysis tools for conflict detection - Coverage for policy priority, edge cases, and environment recovery Status: Draft implementation complete, integration with manager workflows pending.
4.1 KiB
4.1 KiB
ComfyUI Manager Test Suite
This directory contains all tests for the ComfyUI Manager project, organized by module structure.
Directory Structure
tests/
├── setup_test_env.sh # Setup isolated test environment
├── requirements.txt # Test dependencies
├── pytest.ini # Global pytest configuration
├── .gitignore # Ignore test artifacts
│
└── common/ # Tests for comfyui_manager/common/
└── pip_util/ # Tests for pip_util.py
├── README.md # pip_util test documentation
├── conftest.py # pip_util test fixtures
├── pytest.ini # pip_util-specific pytest config
└── test_*.py # Actual test files (to be created)
Quick Start
1. Setup Test Environment (One Time)
cd tests
./setup_test_env.sh
This creates an isolated virtual environment with all test dependencies.
2. Run Tests
# Activate test environment
source test_venv/bin/activate
# Run all tests from root
cd tests
pytest
# Run specific module tests
cd tests/common/pip_util
pytest
# Deactivate when done
deactivate
Test Organization
Tests mirror the source code structure:
| Source Code | Test Location |
|---|---|
comfyui_manager/common/pip_util.py |
tests/common/pip_util/test_*.py |
comfyui_manager/common/other.py |
tests/common/other/test_*.py |
comfyui_manager/module/file.py |
tests/module/file/test_*.py |
Writing Tests
- Create test directory matching source structure
- Add
conftest.pyfor module-specific fixtures - Add
pytest.inifor module-specific configuration (optional) - Create
test_*.pyfiles with actual tests - Document in module-specific README
Test Categories
Use pytest markers to categorize tests:
@pytest.mark.unit
def test_simple_function():
pass
@pytest.mark.integration
def test_complex_workflow():
pass
@pytest.mark.e2e
def test_full_system():
pass
Run by category:
pytest -m unit # Only unit tests
pytest -m integration # Only integration tests
pytest -m e2e # Only end-to-end tests
Coverage Reports
Coverage reports are generated per module:
cd tests/common/pip_util
pytest # Generates htmlcov_pip_util/ and coverage_pip_util.xml
Environment Isolation
Why use venv?
- ✅ Prevents test dependencies from corrupting main environment
- ✅ Allows safe package installation/uninstallation during tests
- ✅ Consistent test results across machines
- ✅ Easy to recreate clean environment
Available Test Modules
- common/pip_util - Policy-based pip package management system tests
- Unit tests for policy loading, parsing, condition evaluation
- Integration tests for policy application (60% of tests)
- End-to-end workflow tests
Adding New Test Modules
- Create directory structure:
tests/module_path/component_name/ - Add
conftest.pywith fixtures - Add
pytest.iniif needed (optional) - Add
README.mddocumenting the tests - Create
test_*.pyfiles
Example:
mkdir -p tests/data_models/config
cd tests/data_models/config
touch conftest.py README.md test_config_loader.py
CI/CD Integration
Tests are designed to run in CI/CD pipelines:
# Example GitHub Actions
- name: Setup test environment
run: |
cd tests
./setup_test_env.sh
- name: Run tests
run: |
source tests/test_venv/bin/activate
pytest tests/
Troubleshooting
Import errors
# Make sure venv is activated
source test_venv/bin/activate
# Verify Python path
python -c "import sys; print(sys.path)"
Tests not discovered
# Check pytest configuration
pytest --collect-only
# Verify test file naming (must start with test_)
ls test_*.py
Clean rebuild
# Remove and recreate test environment
rm -rf test_venv/
./setup_test_env.sh
Resources
- pytest Documentation: https://docs.pytest.org/
- Coverage.py: https://coverage.readthedocs.io/
- Module-specific READMEs: Check each test module directory