Skip to content

feat: set up comprehensive Python testing infrastructure with Poetry#7

Open
llbbl wants to merge 1 commit into
slanj:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: set up comprehensive Python testing infrastructure with Poetry#7
llbbl wants to merge 1 commit into
slanj:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Sep 4, 2025

Set Up Python Testing Infrastructure with Poetry

Summary

This PR establishes a comprehensive testing infrastructure for the YOLO tiling tool project using Poetry as the package manager. The setup provides a complete testing environment ready for immediate use by developers.

Changes Made

Package Management & Dependencies

  • Poetry Setup: Created pyproject.toml with complete Poetry configuration
  • Dependency Migration: Migrated existing dependencies from requirements.txt to Poetry
    • numpy ^1.21.0
    • pandas ^1.3.0
    • Pillow ^8.0.0
    • Shapely ^1.8.0
  • Testing Dependencies: Added development dependencies
    • pytest ^7.0.0
    • pytest-cov ^4.0.0
    • pytest-mock ^3.10.0

Testing Configuration

  • Pytest Configuration: Comprehensive setup in pyproject.toml

    • Test discovery patterns for files, classes, and functions
    • Coverage reporting with 80% threshold
    • HTML and XML coverage reports
    • Strict configuration and custom markers (unit, integration, slow)
    • Warning filters for clean test output
  • Coverage Configuration: Detailed coverage settings

    • Source code inclusion with appropriate exclusions
    • Branch coverage enabled
    • Multiple output formats (HTML in htmlcov/, XML in coverage.xml)

Directory Structure

  • Test Directories: Created organized test structure
    tests/
    ├── __init__.py
    ├── conftest.py (shared fixtures)
    ├── unit/
    │   └── __init__.py
    ├── integration/
    │   └── __init__.py
    └── test_setup_validation.py
    

Shared Testing Utilities

  • Fixtures in conftest.py: Comprehensive shared fixtures including:
    • temp_dir: Temporary directory management
    • sample_image_data: Generated test image data (416x416 RGB)
    • sample_labels_data: YOLO format label data
    • sample_dataset_structure: Complete dataset structure for testing
    • mock_args: Mock command line arguments
    • mock_file_system: File system operation mocking
    • mock_image_operations: PIL Image operation mocking

Development Environment

  • Updated .gitignore: Added comprehensive exclusions for:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, coverage.xml)
    • Python artifacts (__pycache__/, *.pyc, build artifacts)
    • Virtual environments and IDE files
    • Claude Code settings

Validation & Verification

  • Validation Tests: Created test_setup_validation.py with tests for:
    • Testing framework availability
    • Dependency verification
    • Project structure validation
    • Fixture accessibility
    • Test markers functionality
    • Main module import (with graceful handling of system dependencies)

How to Use

Install Dependencies

poetry install

Run Tests

# Run all tests with coverage
poetry run pytest

# Run tests without coverage
poetry run pytest --no-cov

# Run specific test markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

# Run tests with verbose output
poetry run pytest -v

# Generate coverage report only
poetry run pytest --cov-report=html

Test Commands Verified

  • poetry run pytest - Standard test execution
  • python -m pytest - Alternative execution method
  • ✅ Coverage reporting generates HTML and XML outputs
  • ✅ All test markers work correctly
  • ✅ Fixtures are accessible across test modules

Testing Infrastructure Features

  1. Ready-to-Use Environment: Developers can immediately start writing tests
  2. Flexible Test Organization: Separate directories for unit and integration tests
  3. Comprehensive Fixtures: Common testing scenarios pre-built
  4. Coverage Enforcement: 80% coverage threshold with detailed reporting
  5. Multiple Test Types: Support for unit, integration, and slow test markers
  6. System Dependency Handling: Graceful handling of missing system libraries

Notes

  • Poetry Lock File: The poetry.lock file is intentionally tracked to ensure reproducible builds
  • System Dependencies: Some tests may skip if system dependencies (like GEOS for Shapely) are unavailable in CI environments
  • Coverage Configuration: Main module excluded from infrastructure validation tests but included for actual unit tests
  • Test Isolation: Each test gets fresh temporary directories and mocked dependencies

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common scenarios
  4. Run tests with confidence using the configured commands
  5. Monitor code coverage through generated reports

The testing infrastructure is complete and ready for development teams to begin writing comprehensive tests for the YOLO tiling functionality.

- Add Poetry configuration with project metadata and dependencies
- Migrate existing dependencies (numpy, pandas, Pillow, Shapely) from requirements.txt
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Configure pytest with coverage reporting (80% threshold, HTML/XML output)
- Set up test markers (unit, integration, slow) and strict configuration
- Create complete test directory structure (tests/, tests/unit/, tests/integration/)
- Add comprehensive shared fixtures in conftest.py for common test scenarios
- Create validation tests to verify testing infrastructure functionality
- Update .gitignore with testing, Python, and development environment entries
- Configure coverage reporting with appropriate exclusions and thresholds
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