pytools icon indicating copy to clipboard operation
pytools copied to clipboard

feat: Add complete testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Add Complete Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the pytools project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with complete Poetry configuration
  • Dependency Migration: Migrated all dependencies from requirements.txt to Poetry
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • Pytest Configuration:

    • Custom markers for unit, integration, and slow tests
    • Coverage reporting with HTML and XML output
    • Strict mode enabled for better test quality
    • Test discovery patterns configured
  • Coverage Settings:

    • Source set to pytools package
    • Exclusions for test files and common patterns
    • HTML and XML report generation

Project Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures and configuration
├── test_setup_validation.py  # Infrastructure validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (conftest.py)

  • temp_dir - Temporary directory management
  • temp_file - Temporary file creation
  • mock_config - Mock configuration data
  • mock_json_file - JSON file fixtures
  • mock_response - HTTP response mocking
  • mock_qt_app - PyQt5 application mocking
  • sample_image_path - Image file fixtures
  • mock_email_server - Email server mocking
  • env_vars - Environment variable management

Commands Available

  • poetry run test - Run all tests
  • poetry run tests - Alternative command (both work)
  • All standard pytest options are available

Testing the Setup

  1. Install dependencies:

    poetry install
    
  2. Run validation tests:

    poetry run test tests/test_setup_validation.py
    
  3. Run all tests with coverage:

    poetry run test
    

Notes

  • Coverage threshold is currently set to 0% due to the large existing codebase
  • Some dependencies (like PyQt5) may have platform-specific installation issues
  • The infrastructure is ready for developers to start writing unit and integration tests
  • Both poetry.lock file should be committed to ensure reproducible builds

Next Steps

  1. Developers can now write tests in the tests/unit and tests/integration directories
  2. Use the provided fixtures in conftest.py for common testing needs
  3. Mark tests appropriately with @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow
  4. Gradually increase coverage threshold as more tests are added

llbbl avatar Jun 25 '25 13:06 llbbl