KittiSeg icon indicating copy to clipboard operation
KittiSeg copied to clipboard

feat: Add comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 5 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the KittiSeg project using modern Python tooling. The setup provides a solid foundation for writing and running tests with proper coverage reporting.

Changes Made

Package Management

  • Poetry configured as the package manager via pyproject.toml
  • Migrated existing dependencies from requirements.txt
  • Added development dependencies for testing

Testing Framework

  • pytest as the main testing framework
  • pytest-cov for coverage reporting with 80% threshold
  • pytest-mock for mocking utilities

Configuration

  • Comprehensive pytest configuration in pyproject.toml:
    • Test discovery patterns
    • Coverage settings with HTML and XML reports
    • Custom markers for unit, integration, and slow tests
    • Strict mode enabled for better error detection

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures
├── test_infrastructure_validation.py
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Testing Fixtures (in conftest.py)

  • temp_dir: Temporary directory management
  • mock_config: Sample configuration dictionary
  • sample_image: Creates test RGB images
  • sample_label_image: Creates test segmentation images
  • kitti_data_structure: Mock KITTI dataset structure
  • mock_hypes_file: Test configuration files
  • numpy_array_2d/4d: Sample numpy arrays
  • reset_environment: Environment variable isolation
  • capture_logs: Log capture for testing

Additional Updates

  • Updated .gitignore with testing artifacts and Claude settings
  • Created validation tests to verify the infrastructure works correctly

Usage Instructions

Install Dependencies

# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -

# Install project dependencies
poetry install

Running Tests

# Run all tests
poetry run test
# or
poetry run tests

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

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

# Run with different verbosity
poetry run pytest -q  # quiet
poetry run pytest -v  # verbose

Coverage Reports

  • Terminal: Shown automatically after test runs
  • HTML: Generated in htmlcov/ directory
  • XML: Generated as coverage.xml for CI integration

Notes

  • The coverage threshold is set to 80% but can be adjusted in pyproject.toml
  • The validation tests verify that all fixtures and configurations work correctly
  • No actual unit tests for the codebase were written - this PR only sets up the infrastructure
  • Poetry lock file (poetry.lock) should be committed to ensure reproducible builds

llbbl avatar Jun 27 '25 13:06 llbbl