iqiyi-parser icon indicating copy to clipboard operation
iqiyi-parser copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

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.txt to 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: core and nbdler (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 management
  • mock_config: Configuration object mocking
  • mock_video_info: Video information mocking
  • mock_download_info: Download progress mocking
  • mock_cookies: Platform-specific cookie mocking
  • mock_http_response: HTTP response mocking
  • mock_requests: Complete requests library mocking
  • sample_m3u8_content: M3U8 playlist testing
  • sample_html_content: HTML parsing testing
  • mock_file_system: File system operation mocking
  • capture_logs: Log capture for testing
  • mock_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

  1. 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.

  2. Coverage Threshold: Currently set to 0% to allow initial setup. This should be gradually increased as more tests are added to the codebase.

  3. Poetry Lock File: The poetry.lock file is intentionally not gitignored as it ensures reproducible builds across environments.

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests in the tests/unit/ directory
  2. Write integration tests in the tests/integration/ directory
  3. Use the provided fixtures to simplify test writing
  4. Monitor code coverage through the generated reports
  5. Run tests easily using the configured Poetry commands

The testing infrastructure is ready for immediate use!

llbbl avatar Jun 24 '25 04:06 llbbl