feat: Set up comprehensive Python testing infrastructure with Poetry
Add Comprehensive Testing Infrastructure
Summary
This PR sets up a complete testing infrastructure for the VideoCrawlerEngine project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests with proper organization, coverage reporting, and development tooling.
Changes Made
Package Management
- Poetry Configuration: Set up Poetry as the package manager with a properly configured
pyproject.toml - Dependency Migration: Migrated existing dependencies from
requirements.txtto Poetry format with updated versions - Platform-Specific Dependencies: Configured wxPython as optional for Linux environments where GUI testing isn't available
Testing Framework
- pytest: Added as the main testing framework with comprehensive configuration
- pytest-cov: Integrated for code coverage reporting with HTML and XML output formats
- pytest-mock: Included for enhanced mocking capabilities
Project Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── unit/ # Unit tests directory
│ └── __init__.py
├── integration/ # Integration tests directory
│ └── __init__.py
└── test_setup_validation.py # Validation tests
Configuration
pytest Settings (in pyproject.toml)
- Test discovery patterns configured
- Coverage reporting with HTML and XML outputs
- Custom markers defined:
unit,integration,slow - Strict mode enabled for better error detection
Coverage Settings
- Source directories:
coreandnbdler(GUI/handler excluded on Linux due to wxPython) - Coverage threshold temporarily set to 0% (should be increased as tests are added)
- Exclusion patterns for test files and common Python patterns
Test Fixtures (conftest.py)
Comprehensive fixtures provided for common testing needs:
temp_dir: Temporary directory managementmock_config: Configuration object mockingmock_video_info: Video information mockingmock_download_info: Download progress mockingmock_cookies: Platform-specific cookie mockingmock_http_response: HTTP response mockingmock_requests: Complete requests library mockingsample_m3u8_content: M3U8 playlist testingsample_html_content: HTML parsing testingmock_file_system: File system operation mockingcapture_logs: Log capture for testingmock_threading: Threading operation mocking
Development Commands
# Install dependencies
poetry install
# Run all tests
poetry run test
# or
poetry run tests
# Run specific test file
poetry run pytest tests/test_setup_validation.py
# Run with coverage report
poetry run pytest --cov
# Run tests with verbose output
poetry run pytest -v
Updated .gitignore
Added entries for:
- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/,coverage.xml) - Claude settings (
.claude/*) - Build artifacts and virtual environments
- IDE files and logs
Testing the Setup
The validation test file (test_setup_validation.py) verifies:
- Python version compatibility (3.8+)
- Project structure integrity
- Module imports (with platform-specific handling)
- Fixture availability
- Marker registration
- Coverage configuration
- Mocking capabilities
- Command configuration
All validation tests pass, confirming the infrastructure is properly set up.
Notes
-
wxPython on Linux: Due to wxPython's complex build requirements on Linux, it's marked as optional for non-Linux platforms. This allows CI/CD pipelines to run on Linux without GUI dependencies.
-
Coverage Threshold: Currently set to 0% to allow initial setup. This should be gradually increased as more tests are added to the codebase.
-
Poetry Lock File: The
poetry.lockfile is intentionally not gitignored as it ensures reproducible builds across environments.
Next Steps
With this infrastructure in place, developers can now:
- Write unit tests in the
tests/unit/directory - Write integration tests in the
tests/integration/directory - Use the provided fixtures to simplify test writing
- Monitor code coverage through the generated reports
- Run tests easily using the configured Poetry commands
The testing infrastructure is ready for immediate use!