awspx icon indicating copy to clipboard operation
awspx 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

Summary

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

Changes Made

Package Management

  • Set up Poetry as the project's package manager
  • Created pyproject.toml with all project dependencies and development dependencies
  • Configured Poetry to manage both lib and scripts packages

Testing Framework

  • Added pytest with coverage and mocking utilities as development dependencies
  • Configured pytest with:
    • Coverage reporting (HTML, XML, and terminal output)
    • Custom markers for test categorization (unit, integration, slow)
    • Strict test discovery patterns
    • Comprehensive test output formatting

Project Structure

  • Created organized test directory structure:
    tests/
    ├── __init__.py
    ├── conftest.py          # Shared pytest fixtures
    ├── test_setup_validation.py  # Infrastructure validation tests
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    

Testing Fixtures

Added comprehensive shared fixtures in conftest.py:

  • temp_dir - Temporary directory for test files
  • mock_boto3_client - Mock AWS client for testing
  • mock_boto3_session - Mock AWS session
  • mock_neo4j_driver - Mock Neo4j driver for graph database testing
  • sample_aws_config - Sample AWS configuration
  • sample_aws_resource - Sample AWS resource data
  • reset_environment - Auto-reset environment variables
  • mock_console - Mock console for output testing
  • mock_git_repo - Mock git repository

Development Commands

Configured Poetry scripts for running tests:

  • poetry run test - Run all tests with coverage
  • poetry run tests - Alternative command (both work identically)

Both commands support all standard pytest options.

Additional Configuration

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Virtual environment directories
    • IDE files
    • Build artifacts
    • Claude settings directory (.claude/*)

How to Use

  1. Install Poetry (if not already installed):

    curl -sSL https://install.python-poetry.org | python3 -
    
  2. Install dependencies:

    poetry install
    
  3. Run tests:

    # Run all tests
    poetry run test
    
    # Run with specific options
    poetry run test tests/unit/ -v
    
    # Run specific test markers
    poetry run test -m unit
    poetry run test -m "not slow"
    
  4. View coverage report:

    • HTML report: Open htmlcov/index.html in a browser
    • XML report: Available at coverage.xml
    • Terminal report: Shown automatically after test run

Notes

  • The infrastructure is set up with an 80% coverage threshold configured in pyproject.toml
  • All test dependencies are properly isolated as development dependencies
  • The validation tests verify that the infrastructure is working correctly
  • No actual unit tests for the codebase were written - this PR only sets up the infrastructure

Next Steps

With this testing infrastructure in place, developers can now:

  1. Write unit tests for individual modules
  2. Create integration tests for AWS service interactions
  3. Add performance tests using the @pytest.mark.slow marker
  4. Leverage the provided fixtures for consistent test setup

llbbl avatar Jun 25 '25 13:06 llbbl