HomeScript icon indicating copy to clipboard operation
HomeScript copied to clipboard

feat: Set up comprehensive Python testing infrastructure

Open llbbl opened this issue 3 months ago • 0 comments

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the HomeScript project, migrating from the legacy setup.py configuration to a modern Poetry-based development environment.

Changes Made

Package Management Migration

  • Migrated from setup.py to Poetry: Created pyproject.toml with complete project metadata
  • Preserved all existing configuration: Maintained version 5.2, dependencies (requests), and project metadata
  • Added development dependencies: pytest, pytest-cov, pytest-mock as test-group dependencies

Testing Configuration

  • pytest configuration: Comprehensive test discovery, strict markers, verbose output
  • Coverage settings: 80% threshold, HTML/XML reporting, proper source/omit configuration
  • Custom test markers: unit, integration, and slow for test categorization
  • Coverage exclusions: Proper handling of test files, abstracts, and common patterns

Directory Structure

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

Shared Test Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir: Temporary directory management
  • mock_config: Mock configuration data
  • mock_requests_session: HTTP request mocking
  • mock_response: HTTP response mocking
  • mock_environment: Environment variable management
  • sample_device_data: Test data for device operations
  • mock_file_system: File system simulation
  • disable_network_calls: Network isolation for tests

Development Environment

  • Updated .gitignore: Added testing artifacts, virtual environments, IDE files, Claude settings
  • Validation tests: Infrastructure verification tests to ensure everything works
  • Poetry integration: Full dependency management through Poetry

Running Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest

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

# HTML report in htmlcov/
poetry run pytest --cov

# XML report for CI/CD
poetry run pytest --cov --cov-report=xml

Validation

✅ All dependencies install correctly
✅ pytest discovers and runs tests
✅ Coverage reporting generates HTML/XML outputs
✅ Custom markers (unit/integration/slow) work properly
✅ Shared fixtures are available across test modules
✅ Network isolation prevents external calls during testing

Development Notes

  • Poetry lock file: The poetry.lock file is included in version control for reproducible builds
  • Python compatibility: Maintains Python 3.7+ compatibility as specified in original setup.py
  • Coverage threshold: Set to 80% - can be adjusted in pyproject.toml if needed
  • Test organization: Use tests/unit/ for unit tests, tests/integration/ for integration tests

Ready for Development

The testing infrastructure is now ready for developers to:

  1. Write unit tests for individual functions/classes
  2. Create integration tests for end-to-end workflows
  3. Use provided fixtures for common testing scenarios
  4. Generate coverage reports to identify untested code
  5. Run tests in isolation with proper mocking

llbbl avatar Sep 01 '25 21:09 llbbl