Skip to content

Conversation

llbbl
Copy link

@llbbl llbbl commented Sep 4, 2025

Set up comprehensive Python testing infrastructure

Summary

This PR establishes a complete testing infrastructure for the AWS ElastiCache examples repository, providing a unified testing environment across all Python projects in the repository.

Changes Made

Package Management & Dependencies

  • Poetry Configuration: Created pyproject.toml with Poetry setup as the package manager
  • Development Dependencies: Added comprehensive testing stack:
    • pytest (main testing framework)
    • pytest-cov (coverage reporting)
    • pytest-mock (mocking utilities)
    • pytest-asyncio (async testing support)
  • Production Dependencies: Included common libraries used across examples:
    • boto3, redis, valkey-glide (core AWS/cache libraries)
    • flask, streamlit (web frameworks)
    • pandas, numpy (data processing)
    • pydantic, python-dotenv (utilities)

Testing Configuration

  • pytest Configuration:
    • Custom markers: unit, integration, slow
    • Coverage threshold: 80%
    • Multiple report formats: HTML, XML, terminal
    • Strict options for better test quality
  • Coverage Configuration:
    • Source paths covering all Python example directories
    • Comprehensive exclusion patterns
    • HTML and XML report generation

Directory Structure

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

Shared Test Fixtures

Created comprehensive fixtures in conftest.py:

  • Environment: temp_dir, mock_env_vars, sample_data_dir
  • AWS Mocking: mock_boto3_client, mock_aws_credentials
  • Cache Mocking: mock_redis_client, mock_valkey_client
  • Database: mock_database_connection, sample_config
  • Utilities: mock_logger, sample_cache_data

Code Quality Tools

  • Black: Code formatting (line length: 88)
  • isort: Import sorting with Black profile
  • Flake8: Linting
  • mypy: Type checking with strict configuration

Running Tests

Install Dependencies

poetry install

Run Tests

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov

# Run specific test categories
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

# Run with verbose output
poetry run pytest -v

View Coverage Reports

  • Terminal: Coverage summary displayed after test run
  • HTML: Open htmlcov/index.html in browser
  • XML: coverage.xml for CI/CD integration

Configuration Details

Coverage Settings

  • Threshold: 80% minimum coverage required
  • Source Directories: All Python example directories included
  • Exclusions: Test files, virtual environments, build artifacts
  • Reports: HTML (htmlcov/), XML (coverage.xml), and terminal output

Testing Standards

  • Python Version: 3.11+ required
  • Test Discovery: Automatic discovery of test_*.py and *_test.py
  • Markers: Use @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow
  • Fixtures: Extensive shared fixtures available for all tests

Next Steps

With this infrastructure in place, developers can now:

  1. Write Unit Tests: Add tests in tests/unit/ for individual components
  2. Write Integration Tests: Add tests in tests/integration/ for multi-component workflows
  3. Use Shared Fixtures: Leverage pre-configured mocks and test data
  4. Monitor Coverage: Ensure code quality with automated coverage reporting
  5. Run Quality Checks: Use Black, isort, flake8, and mypy for code quality

Validation

The setup includes validation tests (test_setup_validation.py) that verify:

  • ✅ pytest configuration and custom markers
  • ✅ Shared fixtures functionality
  • ✅ Mock clients (Redis, AWS, Database)
  • ✅ Environment variable mocking
  • ✅ Directory structure integrity
  • ✅ Package imports and Python version compatibility

🤖 Generated with Claude Code

- Add Poetry configuration with development dependencies (pytest, pytest-cov, pytest-mock)
- Create complete testing directory structure (tests/, tests/unit/, tests/integration/)
- Configure pytest with custom markers (unit, integration, slow) and coverage reporting
- Add comprehensive shared fixtures in conftest.py for Redis, AWS, and database mocking
- Set up coverage configuration with 80% threshold and HTML/XML reporting
- Include common project dependencies (boto3, redis, valkey-glide, flask, streamlit)
- Update .gitignore with Claude Code settings and testing artifacts
- Add validation tests to verify testing infrastructure setup

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant