QuickDraw icon indicating copy to clipboard operation
QuickDraw copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the QuickDraw Python project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Added pyproject.toml with Poetry configuration for dependency management
  • Package Mode: Set to false since this is an application, not a library
  • Python Version: Set to Python 3.7+ for compatibility with modern testing tools

Testing Dependencies

Added the following development dependencies:

  • pytest (^7.4.0): Core testing framework
  • pytest-cov (^4.1.0): Coverage reporting plugin
  • pytest-mock (^3.11.1): Mocking utilities

Testing Configuration

Configured comprehensive pytest settings in pyproject.toml:

  • Test Discovery: Configured to find tests in the tests/ directory
  • Coverage Settings:
    • Source directories: src/, train.py, draw.py, and all app files
    • Coverage reports: Terminal, HTML (htmlcov/), and XML (coverage.xml)
    • Coverage threshold: Currently set to 0% (should be increased as tests are added)
  • Test Markers: Added unit, integration, and slow markers for test categorization
  • Output Options: Verbose output with short tracebacks

Directory Structure

Created organized testing structure:

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

Shared Fixtures (conftest.py)

Added comprehensive fixtures for common testing needs:

  • temp_dir: Temporary directory creation
  • sample_image_array: Mock image data
  • sample_batch: PyTorch tensor batches
  • mock_config: Configuration dictionaries
  • mock_dataset_path: Mock dataset creation
  • device: PyTorch device selection
  • mock_tensorboard_writer: TensorBoard mocking
  • mock_cv2: OpenCV mocking
  • Random seed resetting for reproducibility

Additional Configuration

  • Updated .gitignore: Added entries for testing artifacts, coverage reports, and Claude settings
  • Poetry Scripts: Both poetry run test and poetry run tests commands are available

How to Use

Install Dependencies

poetry install --with dev

Run Tests

# Run all tests
poetry run pytest

# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration

# Run specific test file
poetry run pytest tests/test_setup_validation.py

View Coverage Reports

  • Terminal: Coverage is shown automatically after test runs
  • HTML: Open htmlcov/index.html in a browser
  • XML: Available at coverage.xml for CI/CD integration

Validation

The setup includes a comprehensive validation test (test_setup_validation.py) that verifies:

  • All testing dependencies are properly installed
  • Project structure is correct
  • All fixtures are working properly
  • Test markers are configured
  • Mocking capabilities are functional

All validation tests are passing ✅

Next Steps

  1. Developers can now start writing unit tests in tests/unit/
  2. Integration tests can be added to tests/integration/
  3. Coverage threshold should be gradually increased as tests are added
  4. Consider adding pre-commit hooks for running tests

Notes

  • The project uses Poetry's package-mode=false since it's an application
  • Coverage warnings about unimported modules are expected until actual tests are written
  • The testing infrastructure supports all major testing patterns (mocking, fixtures, markers, coverage)

llbbl avatar Jun 26 '25 12:06 llbbl