zkp-hmac-communication-python
zkp-hmac-communication-python 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 Zero-Knowledge Python project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Setup: Created
pyproject.tomlwith complete project configuration - Dependency Migration: Migrated existing dependencies from
requirements.txtto Poetry - Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies
Testing Configuration
-
pytest Configuration:
- Set up test discovery patterns for
test_*.pyand*_test.pyfiles - Configured strict mode with proper error handling
- Added custom markers:
unit,integration, andslow
- Set up test discovery patterns for
-
Coverage Settings:
- Configured 80% coverage threshold (currently set to 0 for infrastructure validation)
- Set up HTML, XML, and terminal coverage reports
- Excluded test files and
__init__.pyfiles from coverage
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_infrastructure_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Testing Fixtures
Created comprehensive fixtures in conftest.py:
temp_dir: Temporary directory managementmock_config: Configuration dictionary for testingmock_logger: Mock logger with all standard methodssample_data: Sample test data structuresmock_file_system: File system operations helperenvironment_variables: Safe environment variable manipulationmock_random: Deterministic random number generationcapture_logs: Log capture for testing
Additional Setup
- Scripts: Added
poetry run testandpoetry run testscommands - .gitignore: Updated with comprehensive Python testing patterns and Claude-specific entries
- Validation Tests: Created tests to verify the infrastructure works correctly
How to Use
-
Install dependencies:
poetry install -
Run tests:
poetry run test # or poetry run tests -
Run specific test markers:
poetry run pytest -m unit # Run only unit tests poetry run pytest -m integration # Run only integration tests poetry run pytest -m "not slow" # Skip slow tests -
Generate coverage report:
poetry run pytest --cov-report=html # Open htmlcov/index.html in browser
Notes
- The coverage threshold is currently set to 0% in
pyproject.tomlto allow the infrastructure validation tests to pass. This should be changed to 80% when actual tests are added. - Poetry will create a virtual environment in
.venv/directory - The
poetry.lockfile should be committed to ensure reproducible builds - All test dependencies are properly isolated as development dependencies
Next Steps
With this infrastructure in place, developers can now:
- Write unit tests in the
tests/unit/directory - Write integration tests in the
tests/integration/directory - Use the provided fixtures for common testing scenarios
- Run tests with coverage reporting to ensure code quality