Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 3, 2025

Set up comprehensive Python testing infrastructure

Summary

This PR establishes a complete testing infrastructure for the PDF Compressor project, migrating from a simple requirements.txt setup to a professional Poetry-based development environment with comprehensive testing capabilities.

Changes Made

  • Package Management Migration: Migrated from requirements.txt to Poetry with pyproject.toml configuration
  • Testing Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies
  • Test Configuration: Configured pytest with comprehensive settings including:
    • 80% coverage threshold requirement
    • HTML and XML coverage report generation
    • Custom markers for unit, integration, and slow tests
    • Strict configuration and verbose output
  • Directory Structure: Created organized test directory structure:
    tests/
    ├── __init__.py
    ├── conftest.py
    ├── test_setup_validation.py
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    
  • Shared Fixtures: Created comprehensive conftest.py with reusable test fixtures:
    • temp_dir: Temporary directory for test files
    • sample_pdf_path: Mock PDF files for testing
    • mock_qapplication: PyQt application mocking
    • mock_subprocess: Subprocess command mocking
    • compression_test_data: Test data for compression operations
  • Validation Tests: Added complete test suite to validate infrastructure setup
  • Environment Configuration: Updated .gitignore with testing-related entries and IDE configurations

Testing Infrastructure Components

  1. pytest Configuration (pyproject.toml):

    • Test discovery patterns
    • Coverage settings with 80% threshold
    • HTML and XML report generation
    • Custom test markers
  2. Coverage Configuration:

    • Source directory inclusion (src/)
    • Exclusion of test files and common patterns
    • Multiple report formats (HTML, XML, terminal)
  3. Shared Test Fixtures (tests/conftest.py):

    • File system mocking and temporary directories
    • PyQt widget mocking for GUI testing
    • Sample configuration data
    • Compression test data sets

Running Tests

After this setup, developers can run tests using:

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=src

# Run specific test types
poetry run pytest -m unit          # Unit tests only
poetry run pytest -m integration   # Integration tests only
poetry run pytest -m slow          # Slow tests only

# Generate coverage reports
poetry run pytest --cov=src --cov-report=html

Coverage Reports

The setup generates coverage reports in multiple formats:

  • HTML: htmlcov/index.html - Interactive coverage report
  • XML: coverage.xml - For CI/CD integration
  • Terminal: Summary displayed after test runs

Dependencies Migration

Before: requirements.txt

PyQt6
humanize

After: pyproject.toml with Poetry

  • Production dependencies: PyQt6, humanize
  • Test dependencies: pytest, pytest-cov, pytest-mock

Next Steps

This infrastructure is ready for developers to:

  1. Write unit tests for the PDF compression logic
  2. Create integration tests for the full application workflow
  3. Add GUI tests for the PyQt interface
  4. Integrate with CI/CD pipelines using the coverage reports

The validation tests confirm that all fixtures, markers, and coverage reporting work correctly. The setup follows Python testing best practices and provides a solid foundation for comprehensive test coverage.

- Migrated from requirements.txt to Poetry package management
- Added pytest, pytest-cov, and pytest-mock as test dependencies
- Configured pytest with 80% coverage threshold and HTML/XML reports
- Created tests/ directory structure with unit/ and integration/ subdirectories
- Added comprehensive conftest.py with shared fixtures for testing
- Set up custom pytest markers (unit, integration, slow)
- Updated .gitignore with testing-related entries and Claude Code settings
- Added validation tests to verify infrastructure setup
- Generated coverage reports in HTML and XML formats
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