mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2026-05-15 19:37:24 +08:00
| .. | ||
| cli | ||
| common | ||
| e2e | ||
| playwright | ||
| .gitignore | ||
| pytest.ini | ||
| README.md | ||
| requirements.txt | ||
| setup_test_env.sh | ||
| test_git_compat.py | ||
| test_nightly_cnr_fallback.py | ||
| test_unified_dep_resolver.py | ||
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