zkp-hmac-communication-python icon indicating copy to clipboard operation
zkp-hmac-communication-python copied to clipboard

feat: set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 0 comments

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.toml with complete project configuration
  • Dependency Migration: Migrated existing dependencies from requirements.txt to Poetry
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Configuration:

    • Set up test discovery patterns for test_*.py and *_test.py files
    • Configured strict mode with proper error handling
    • Added custom markers: unit, integration, and slow
  • 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__.py files 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 management
  • mock_config: Configuration dictionary for testing
  • mock_logger: Mock logger with all standard methods
  • sample_data: Sample test data structures
  • mock_file_system: File system operations helper
  • environment_variables: Safe environment variable manipulation
  • mock_random: Deterministic random number generation
  • capture_logs: Log capture for testing

Additional Setup

  • Scripts: Added poetry run test and poetry run tests commands
  • .gitignore: Updated with comprehensive Python testing patterns and Claude-specific entries
  • Validation Tests: Created tests to verify the infrastructure works correctly

How to Use

  1. Install dependencies:

    poetry install
    
  2. Run tests:

    poetry run test
    # or
    poetry run tests
    
  3. 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
    
  4. 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.toml to 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.lock file 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:

  1. Write unit tests in the tests/unit/ directory
  2. Write integration tests in the tests/integration/ directory
  3. Use the provided fixtures for common testing scenarios
  4. Run tests with coverage reporting to ensure code quality

llbbl avatar Jun 24 '25 05:06 llbbl