Comfyui-ChatTTS icon indicating copy to clipboard operation
Comfyui-ChatTTS copied to clipboard

feat: Set up comprehensive Python testing infrastructure

Open llbbl opened this issue 3 months ago • 0 comments

Python Testing Infrastructure Setup

Summary

This PR sets up a comprehensive testing infrastructure for the ChatTTS and OpenVoice integration project, providing a complete foundation for writing and running tests.

Changes Made

Package Management

  • Configured Poetry as the primary package manager
  • Created pyproject.toml with complete project configuration
  • Migrated dependencies from requirements.txt to Poetry format
  • Added test dependencies: pytest, pytest-cov, pytest-mock

Testing Configuration

  • pytest configuration with coverage reporting (HTML, XML, terminal output)
  • Custom test markers: unit, integration, slow for test categorization
  • Strict testing options with comprehensive test discovery patterns
  • Coverage settings with source inclusion and exclusion patterns

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and test utilities
├── unit/
│   ├── __init__.py
│   ├── conftest.py         # Unit-specific fixtures
│   └── test_basic_validation.py
├── integration/
│   └── __init__.py
├── test_infrastructure.py  # Standalone validation tests
├── test_infrastructure_validation.py
└── mock_modules.py         # ComfyUI dependency mocks

Shared Testing Utilities

  • Comprehensive fixtures for temporary directories, mock configurations, audio data
  • ComfyUI dependency mocking to handle project-specific imports
  • Test environment setup with automatic cleanup and isolation
  • Mock file system utilities for testing file operations

Development Workflow

  • Updated .gitignore with testing artifacts, build outputs, IDE files
  • Validation tests to ensure infrastructure works correctly
  • Support for multiple test types: unit, integration, parametrized tests
  • Error handling validation and exception testing capabilities

Testing Infrastructure Components

Core Testing Features

  • pytest for test discovery and execution
  • pytest-cov for code coverage reporting
  • pytest-mock for mocking and patching
  • Custom markers for test categorization
  • Parametrized testing support
  • Fixture-based test utilities

Coverage Configuration

  • Source tracking: Configured to track nodes package
  • Report formats: HTML, XML, and terminal output
  • Exclusion patterns: Test files, __init__.py, and common patterns
  • Coverage thresholds: Configurable for CI/CD integration

Mock and Testing Utilities

  • ComfyUI mocking: Handles folder_paths and comfy module dependencies
  • File system mocking: Temporary directories, files, and mock project structures
  • Configuration mocking: Mock model configurations and audio data
  • Environment isolation: Automatic environment variable reset

Running Tests

Basic Commands

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=nodes

# Run specific test types
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

# Run with verbose output
poetry run pytest -v

Coverage Reports

# Generate HTML coverage report
poetry run pytest --cov=nodes --cov-report=html

# Generate XML coverage report (for CI/CD)
poetry run pytest --cov=nodes --cov-report=xml

# Terminal coverage report
poetry run pytest --cov=nodes --cov-report=term-missing

Validation

The infrastructure includes comprehensive validation tests that verify:

  • pytest functionality and version compatibility
  • Project structure and file organization
  • Test markers and categorization
  • Fixture availability and functionality
  • Mocking capabilities and patch operations
  • Parametrized testing support
  • Error handling and exception testing
  • Coverage reporting integration

Next Steps

With this infrastructure in place, developers can:

  1. Write unit tests for individual functions and classes
  2. Create integration tests for component interactions
  3. Add performance tests using the slow marker
  4. Generate coverage reports to track test completeness
  5. Run tests in CI/CD pipelines with consistent results

Notes

  • ComfyUI Dependencies: Mock modules are provided for folder_paths and comfy dependencies
  • Coverage Configuration: Currently set to track the nodes package, easily adjustable
  • Test Isolation: Each test runs in an isolated environment with automatic cleanup
  • Extensible: Easy to add new fixtures, markers, and test utilities as needed

llbbl avatar Sep 03 '25 14:09 llbbl