localrf icon indicating copy to clipboard operation
localrf copied to clipboard

feat: Add comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

Add Python Testing Infrastructure

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

Summary of Changes

Package Management

  • Created pyproject.toml with Poetry configuration
  • Set up the project as localtensorf with proper metadata
  • Configured Poetry to manage dependencies and virtual environments

Testing Dependencies

Added the following development dependencies:

  • pytest (v7.4.0+): Main testing framework
  • pytest-cov (v4.1.0+): Coverage reporting plugin
  • pytest-mock (v3.11.0+): Mocking utilities for tests

Testing Configuration

Configured comprehensive testing settings in pyproject.toml:

  • Test discovery patterns for test_*.py and *_test.py files
  • Coverage reporting with 80% threshold requirement
  • Multiple coverage output formats (terminal, HTML, XML)
  • Custom test markers: unit, integration, and slow
  • Proper source inclusion and exclusion patterns for coverage

Directory Structure

Created a well-organized testing structure:

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

Shared Fixtures (conftest.py)

Added comprehensive fixtures for common testing needs:

  • temp_dir and temp_file: Temporary file system resources
  • mock_config: Mock configuration objects
  • sample_data: Sample data for testing
  • mock_model and mock_dataset: ML-specific mocks
  • json_file and config_file: Temporary config files
  • mock_logger: Logging mock utilities
  • mock_file_system: File system operation mocks
  • capture_logs: Log capturing for assertions
  • benchmark_timer: Simple performance timing
  • And more...

Additional Setup

  • Updated .gitignore with testing artifacts (.pytest_cache/, htmlcov/, etc.)
  • Added Claude-specific entries to .gitignore (.claude/*)
  • Created validation tests to ensure the infrastructure works correctly

How to Run Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest

Run Tests with Coverage

poetry run pytest --cov

Run Specific Test Categories

# Unit tests only
poetry run pytest -m unit

# Integration tests only
poetry run pytest -m integration

# Exclude slow tests
poetry run pytest -m "not slow"

Generate Coverage Reports

Coverage reports are automatically generated in multiple formats:

  • Terminal output with missing lines
  • HTML report in htmlcov/ directory
  • XML report as coverage.xml

Notes

  • The project uses Poetry for dependency management, ensuring consistent environments
  • Coverage threshold is set to 80% to maintain high code quality
  • All test infrastructure has been validated with passing tests
  • The setup is ready for developers to immediately start writing tests
  • No actual unit tests for the codebase were written - only infrastructure setup

llbbl avatar Jun 16 '25 18:06 llbbl