StreamDiffusion-NDI icon indicating copy to clipboard operation
StreamDiffusion-NDI copied to clipboard

feat: Set up complete testing infrastructure with Poetry

Open llbbl opened this issue 3 months ago โ€ข 0 comments

Set up Complete Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the StreamDiffusion NDI project, migrating from a basic requirements.txt setup to a professional Poetry-managed development environment with full testing capabilities.

Key Changes Made

  • ๐Ÿ“ฆ Package Management: Migrated from requirements.txt to Poetry with proper dependency management
  • ๐Ÿงช Testing Framework: Set up pytest with comprehensive configuration including coverage reporting
  • ๐Ÿ“ Directory Structure: Created organized test directories (tests/unit/, tests/integration/)
  • ๐Ÿ”ง Configuration: Added complete testing configuration in pyproject.toml
  • ๐Ÿ“‹ Fixtures: Created comprehensive shared fixtures in conftest.py for common testing patterns
  • ๐Ÿ“Š Coverage: Configured coverage reporting with 80% threshold, HTML and XML output formats
  • ๐Ÿท๏ธ Markers: Set up custom test markers (unit, integration, slow) for test categorization
  • โš™๏ธ Scripts: Added Poetry scripts for easy test execution (poetry run test, poetry run tests)
  • ๐Ÿ™ˆ Gitignore: Created comprehensive .gitignore with testing and development entries

Testing Infrastructure Components

Package Management

  • Poetry: Modern dependency management with proper virtual environment handling
  • Dependencies: All original dependencies preserved (opencv-python, python-osc)
  • Optional Dependencies: ndi-python made optional due to platform compatibility

Testing Dependencies

  • pytest: Main testing framework with comprehensive configuration
  • pytest-cov: Coverage reporting with multiple output formats
  • pytest-mock: Advanced mocking utilities for test isolation

Test Configuration Features

  • Test Discovery: Automatic discovery of test files and functions
  • Coverage: 80% coverage threshold with HTML, XML, and terminal reporting
  • Markers: Custom markers for test categorization and selective running
  • Strict Mode: Strict configuration and marker validation for reliability

Shared Fixtures Available

  • temp_dir, temp_file: Temporary file system utilities
  • sample_config, mock_config_file: Configuration management fixtures
  • mock_opencv, mock_ndi, mock_osc_client: Mock external dependencies
  • sample_image_array: Mock image data for computer vision testing
  • mock_environment_vars: Environment isolation for testing
  • capture_logs: Log capture and assertion utilities

Instructions for Running Tests

Basic Test Commands

# Install dependencies
poetry install

# Run all tests
poetry run test
# or
poetry run tests

# Run with verbose output
poetry run pytest -v

# Run specific test categories
poetry run pytest -m unit          # Unit tests only
poetry run pytest -m integration   # Integration tests only
poetry run pytest -m "not slow"    # Skip slow tests

Coverage Reports

# Generate HTML coverage report (opens in htmlcov/index.html)
poetry run pytest --cov-report=html

# View coverage in terminal
poetry run pytest --cov-report=term-missing

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

Development Workflow

# Run tests in watch mode during development
poetry run pytest --maxfail=1 -x

# Run only failed tests from last run
poetry run pytest --lf

# Show available fixtures
poetry run pytest --fixtures

Notes and Considerations

  • NDI Compatibility: The ndi-python dependency was made optional due to platform-specific wheel availability issues. This ensures the testing infrastructure works across different environments.
  • Coverage Threshold: Set to 80% but can be adjusted in pyproject.toml based on project requirements.
  • Test Isolation: Each test runs in isolation with automatic cleanup of temporary resources.
  • Future-Ready: The infrastructure supports both unit and integration testing patterns, ready for immediate use.

Validation

  • โœ… All dependencies install successfully
  • โœ… Test discovery finds test files correctly
  • โœ… Custom markers work as expected
  • โœ… Shared fixtures are properly available across tests
  • โœ… Coverage reporting generates HTML, XML, and terminal output
  • โœ… Poetry scripts execute tests correctly
  • โœ… Test isolation prevents cross-test interference

The testing infrastructure is now ready for developers to begin writing comprehensive tests for the StreamDiffusion NDI codebase.

llbbl avatar Sep 04 '25 15:09 llbbl