1. requirements.txt 限定 py<1.11.0 和 pytest<8.0.0,避免 AttributeError: module 'py' has no attribute 'path' 2. CI 安装步骤强制指定兼容版本,确保 GitHub Actions 稳定通过 3. 本地推荐使用 venv 隔离依赖,避免系统包冲突 4. 测试脚本 run_tests.py 支持自动适配环境,纯Python/torch/pytest 均可用 fix(ci/deps): Fix pytest/py compatibility, improve venv support 1. requirements.txt restricts py<1.11.0 and pytest<8.0.0 to avoid AttributeError 2. CI install step enforces compatible versions for stable GitHub Actions 3. Local usage recommends venv for dependency isolation 4. run_tests.py auto-detects environment, works for pure Python/torch/pytest
ComfyUI DCI Extension - Test Suite
This directory contains comprehensive unit tests for the ComfyUI DCI Extension.
Test Structure
Unit Tests (New)
test_dci_format.py- Tests for DCI format creation and parsingtest_pure_python_ar.py- Tests for pure Python AR implementationtest_comfyui_nodes.py- Tests for ComfyUI nodestest_runner.py- Test runner for all unit testsconftest.py- Pytest configuration and fixtures
Legacy Tests (Integration)
The existing test files serve as integration tests:
DCI Preview and UI Tests
test_dci_preview_*.py- DCI preview functionality teststest_dci_preview_node_fix.py- DCI preview node bug fixestest_dci_preview_simple.py- Simple DCI preview teststest_dci_preview_ui.py- UI-related preview teststest_font_size_*.py- Font size handling tests
File Processing Tests
test_dci_file_saver.py- DCI file saving teststest_binary_*.py- Binary file handling teststest_real_dci_files.py- Real DCI file processing teststest_layer_system.py- DCI layer system tests
Node Tests
test_node_*.py- Node registration and connectivity teststest_new_dci_nodes.py- New DCI node functionality teststest_structure_node.py- DCI structure analysis tests
Quality and Feature Tests (Moved from root)
test_advanced_compression.py- Advanced compression feature teststest_border_color.py- Border color functionality teststest_categories.py- Category system teststest_quality_feature.py- Image quality feature teststest_transparent_preview.py- Transparent image preview teststest_pure_python_implementation.py- Pure Python implementation teststest_pure_python_simple.py- Simple pure Python testssimple_quality_test.py- Simple quality testing script
Test Assets
test_preview_*.png- Test preview images (blue, dark, light themes)test_transparent_preview.png- Transparent preview test imagetest_output.dci- Sample DCI output file for testing
Verification Scripts
verify_*.py- Various verification and validation scripts
Running Tests
Using the Test Runner
# Run all unit tests
cd tests
python test_runner.py
# Run specific test module
python test_runner.py test_dci_format
Using unittest
# Run all unit tests
python -m unittest discover tests -p "test_*.py" -v
# Run specific test class
python -m unittest tests.test_dci_format.TestDCIFormat -v
# Run specific test method
python -m unittest tests.test_dci_format.TestDCIFormat.test_basic_dci_creation -v
Using pytest (if available)
# Run all tests
python -m pytest tests/ -v
# Run with coverage
python -m pytest tests/ --cov=py --cov-report=html
# Run only unit tests
python -m pytest tests/ -m unit
# Run only integration tests
python -m pytest tests/ -m integration
Using Makefile
# Run all tests
make test
# Run unit tests only
make test-unit
# Run integration tests
make test-integration
# Run with coverage
make test-coverage
GitHub Actions
Tests are automatically run on GitHub Actions when:
- Code is pushed to main/master/develop branches
- Pull requests are created
- Manual workflow dispatch is triggered
The CI pipeline runs tests on multiple Python versions (3.8, 3.9, 3.10, 3.11) and includes:
- Unit tests
- Integration tests
- Cross-platform testing (Linux, Windows, macOS)
- Code coverage reporting
Test Categories
Unit Tests
- DCI Format Tests: Test DCI file creation, parsing, and structure validation
- Pure Python AR Tests: Test AR archive creation and extraction without external dependencies
- ComfyUI Node Tests: Test node initialization, execution, and integration
Integration Tests
- Legacy Test Files: Existing test files that test complete workflows
- Real File Processing: Tests with actual DCI files and real-world scenarios
- Cross-platform Compatibility: Tests that verify functionality across different operating systems
Test Features
Automatic Test Discovery
- Tests are automatically discovered by pattern matching (
test_*.py) - Test classes must start with
Test - Test methods must start with
test_
Fixtures and Setup
- Temporary directories are automatically created and cleaned up
- Sample data is provided through fixtures
- Test environment is properly isolated
Skip Conditions
- Tests are automatically skipped if required modules are not available
- This allows tests to run even in incomplete environments
- Graceful degradation for missing dependencies
Coverage Reporting
- Code coverage is measured and reported
- HTML coverage reports are generated
- Coverage data is uploaded to Codecov (optional)
Writing New Tests
Unit Test Template
import unittest
import tempfile
import shutil
class TestNewFeature(unittest.TestCase):
def setUp(self):
"""Set up test environment"""
self.test_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.test_dir)
def test_feature_functionality(self):
"""Test specific functionality"""
# Test implementation
self.assertTrue(True) # Replace with actual test
@unittest.skipIf(condition, "reason")
def test_conditional_feature(self):
"""Test that may be skipped"""
# Test implementation
pass
Best Practices
- Isolation: Each test should be independent and not rely on other tests
- Cleanup: Use
setUp()andtearDown()oraddCleanup()for resource management - Descriptive Names: Test names should clearly describe what is being tested
- Skip Conditions: Use
@unittest.skipIf()for tests that require specific conditions - Assertions: Use appropriate assertion methods (
assertEqual,assertTrue, etc.) - Documentation: Include docstrings explaining what each test does
Troubleshooting
Common Issues
- Import Errors: Make sure the project path is correctly added to
sys.path - Missing Dependencies: Install test dependencies with
make dev-install - Permission Errors: Ensure test directories are writable
- Path Issues: Use
os.path.join()for cross-platform path handling
Debug Mode
Run tests with verbose output to see detailed information:
python -m unittest tests.test_module -v
Test Isolation
If tests are interfering with each other:
- Check that temporary files are properly cleaned up
- Ensure global state is not modified
- Use separate test directories for each test
Contributing
When adding new functionality:
- Write unit tests for new features
- Update existing tests if behavior changes
- Ensure all tests pass before submitting
- Add integration tests for complex workflows
- Update this documentation if needed