amazon-elasticache-samples
amazon-elasticache-samples copied to clipboard
feat: Set up comprehensive Python testing infrastructure
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.tomlwith 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
- Custom markers:
- 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.htmlin browser - XML:
coverage.xmlfor 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_*.pyand*_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:
- Write Unit Tests: Add tests in
tests/unit/for individual components - Write Integration Tests: Add tests in
tests/integration/for multi-component workflows - Use Shared Fixtures: Leverage pre-configured mocks and test data
- Monitor Coverage: Ensure code quality with automated coverage reporting
- 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