Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 4, 2025

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.

- Migrated from requirements.txt to Poetry package management
- Added comprehensive testing configuration in pyproject.toml
- Set up pytest with coverage reporting, custom markers, and strict options
- Created modular test directory structure with unit/integration separation
- Added comprehensive shared fixtures in conftest.py for common testing needs
- Configured coverage reporting with 80% threshold, HTML and XML output
- Made ndi-python optional due to platform compatibility issues
- Added complete .gitignore with testing and development entries
- Set up Poetry scripts for `poetry run test` and `poetry run tests`
- Created validation tests to verify infrastructure setup
- All tests passing with proper fixture isolation and marker configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant