StreamDiffusion-NDI
StreamDiffusion-NDI copied to clipboard
feat: Set up complete testing infrastructure with Poetry
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.txtto 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.pyfor 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
.gitignorewith 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-pythonmade 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-pythondependency 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.tomlbased 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.