Skip to content

feat: set up comprehensive Python testing infrastructure with Poetry #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 24, 2025

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

- Set up Poetry as package manager with pyproject.toml
- Migrated dependencies from requirements.txt to Poetry
- Added testing dependencies: pytest, pytest-cov, pytest-mock
- Configured pytest with coverage reporting and custom markers
- Created test directory structure with unit/integration subdirectories
- Added comprehensive shared fixtures in conftest.py
- Created validation tests to verify infrastructure setup
- Updated .gitignore with testing and Claude-specific entries
- Configured coverage thresholds and reporting formats
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