ElectricEye
ElectricEye copied to clipboard
feat: set up comprehensive Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the ElectricEye project, migrating from basic requirements.txt to Poetry for modern dependency management and setting up pytest with full coverage support.
Changes Made
Package Management
- Migrated to Poetry: Created
pyproject.tomlwith Poetry configuration - Migrated dependencies: Moved all dependencies from
requirements.txtto Poetry - Added test dependencies:
pytest(^8.0.0) - Main testing frameworkpytest-cov(^5.0.0) - Coverage reportingpytest-mock(^3.14.0) - Mocking utilitiesblack(^24.0.0) - Code formatting (already in requirements-dev.txt)
Testing Configuration
-
Pytest configuration in
pyproject.toml:- Strict markers and configuration
- Test discovery patterns for
test_*.pyand*_test.py - Custom markers:
unit,integration,slow - Coverage settings with 80% threshold
- HTML and XML coverage reports
-
Coverage configuration:
- Source set to
eeauditorpackage - Branch coverage enabled
- Proper exclusions for test files and virtual environments
- Report precision and missing line display
- Source set to
Directory Structure
/workspace/
├── pyproject.toml # Poetry and tool configurations
├── tests/ # Test root directory
│ ├── __init__.py
│ ├── conftest.py # Shared fixtures
│ ├── test_setup_validation.py # Infrastructure validation
│ ├── unit/ # Unit tests directory
│ │ └── __init__.py
│ └── integration/ # Integration tests directory
│ └── __init__.py
└── eeauditor/tests/ # Existing tests (preserved)
Shared Fixtures (conftest.py)
Created comprehensive fixtures for common testing patterns:
temp_dir- Temporary directory managementmock_config- Mock configuration for cloud providersmock_aws_client/session- AWS service mockingsample_finding- Security Hub finding templatemock_env_vars- Environment variable mockingjson_file/temp_file- File handling helpersmock_cloud_provider- Generic cloud provider mockcapture_logs- Log capture for testingmock_datetime- Date/time mocking
Additional Updates
- Updated .gitignore with:
- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/, etc.) - Claude settings (
.claude/*) - Build artifacts and virtual environments
- IDE files and temporary files
- Note:
poetry.lockis NOT ignored (important for reproducible builds)
- Testing artifacts (
Running Tests
After setting up the environment with Poetry:
# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install
# Run all tests
poetry run pytest
# Alternative command (both work)
poetry run test
poetry run tests
# Run with specific options
poetry run pytest -v # Verbose output
poetry run pytest -m unit # Only unit tests
poetry run pytest -m integration # Only integration tests
poetry run pytest --no-cov # Skip coverage
poetry run pytest tests/unit/ # Run specific directory
Notes
- Python Version: Updated to
^3.9due to pandas requirements - Existing Tests: The existing tests in
eeauditor/tests/are preserved and can be moved to the new structure as needed - Coverage Threshold: Set to 80% to encourage good test coverage
- No Actual Tests Written: This PR only sets up infrastructure; actual unit tests for the codebase should be written separately
- Validation Tests: Included
test_setup_validation.pyto verify the testing infrastructure works correctly
Next Steps
- Developers can now start writing unit tests in
tests/unit/ - Integration tests can be added to
tests/integration/ - Existing tests from
eeauditor/tests/can be refactored to use the new fixtures - Consider adding pre-commit hooks for running tests
- Set up CI/CD pipeline to run tests automatically