llama3.np icon indicating copy to clipboard operation
llama3.np copied to clipboard

feat: Add comprehensive Python testing infrastructure

Open llbbl opened this issue 6 months ago โ€ข 0 comments

Add Comprehensive Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the Python project, providing a foundation for writing and running tests with proper tooling and configuration.

Changes Made

๐Ÿ“ฆ Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration as the package manager
  • Dependency Migration: Migrated existing numpy dependency from requirements.txt
  • Poetry Lock: Added poetry.lock to .gitignore to avoid version conflicts

๐Ÿงช Testing Dependencies

Added as development dependencies:

  • pytest (^7.4.0) - Main testing framework
  • pytest-cov (^4.1.0) - Coverage reporting plugin
  • pytest-mock (^3.11.0) - Mocking utilities

โš™๏ธ Configuration

pytest Configuration (pyproject.toml)

  • Test discovery patterns for test_*.py and *_test.py files
  • Strict markers and configuration enforcement
  • Coverage reporting with HTML and XML output
  • Custom markers: unit, integration, slow

Coverage Configuration

  • Source includes all project files
  • Excludes test files, cache directories, virtual environments
  • Configured exclusion patterns for non-testable code

๐Ÿ“ Directory Structure

tests/
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ conftest.py          # Shared fixtures and configuration
โ”œโ”€โ”€ test_setup_validation.py  # Validation tests
โ”œโ”€โ”€ unit/
โ”‚   โ””โ”€โ”€ __init__.py
โ””โ”€โ”€ integration/
    โ””โ”€โ”€ __init__.py

๐Ÿ”ง Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory management
  • mock_config: Configuration dictionary for testing
  • sample_text_data: Sample text data for testing
  • mock_model_weights: Mock file creation
  • env_var_backup: Environment variable isolation
  • reset_random_seeds: Reproducible test runs
  • capture_logs: Log message capture

๐Ÿ“ Additional Updates

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

Usage Instructions

Install Dependencies

poetry install

Run Tests

# Run all tests
poetry run test

# Alternative command (both work)
poetry run tests

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

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

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

Coverage Reports

  • Terminal: Coverage summary shown after each test run
  • HTML Report: Generated in htmlcov/ directory
  • XML Report: Generated as coverage.xml for CI integration

Notes

  • The infrastructure is set up but does not include actual unit tests for the codebase
  • Coverage threshold is currently not enforced (removed --cov-fail-under=80 from default options)
  • All pytest standard options remain available for use
  • The validation test suite confirms all components are working correctly

Validation Results

All validation tests pass successfully:

  • โœ… pytest installation verified
  • โœ… Project structure validated
  • โœ… Fixtures working correctly
  • โœ… Custom markers registered
  • โœ… Coverage configuration functional
  • โœ… Both test and tests commands operational

llbbl avatar Jun 16 '25 23:06 llbbl