Skip to content

feat: add comprehensive Python testing infrastructure with Poetry #37

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: master
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 18, 2025

Add Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the pysift project using Poetry for dependency management and pytest for testing.

Changes Made

1. Package Management

  • Poetry Setup: Created pyproject.toml with project metadata and dependencies
  • Dependency Migration: Migrated dependencies from README to Poetry configuration
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

2. Testing Configuration

  • pytest Configuration:

    • Configured test discovery patterns
    • Set up coverage reporting with HTML and XML output
    • Added custom markers: unit, integration, slow, performance
    • Enabled strict mode and verbose output
    • Coverage threshold set to 0% (should be changed to 80% when actual tests are added)
  • Coverage Configuration:

    • Source directory set to pysift
    • Branch coverage enabled
    • Exclusion patterns for non-testable code
    • HTML and XML report generation

3. Testing Structure

tests/
├── __init__.py
├── conftest.py              # Shared pytest fixtures
├── test_setup_validation.py # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

4. Pytest Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir: Temporary directory for test files
  • sample_image: Color test image (100x100)
  • grayscale_image: Grayscale test image
  • sample_keypoints: OpenCV KeyPoint objects
  • sample_descriptors: Mock SIFT descriptors
  • mock_config: Configuration dictionary
  • test_image_path: Saved test image path
  • capture_stdout: Stdout capture utility
  • mock_sift_detector: Mocked SIFT detector

5. Poetry Scripts

Added convenient test commands:

  • poetry run test - Run all tests with coverage
  • poetry run tests - Alternative command (both work)

6. Additional Changes

  • Created .gitignore with comprehensive Python patterns
  • Added validation tests to verify the infrastructure works
  • Used opencv-python-headless to avoid GUI dependencies in tests

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    poetry run test        # or
    poetry run tests       # or
    poetry run pytest      # with custom options
  3. Run specific test categories:

    poetry run pytest -m unit              # Unit tests only
    poetry run pytest -m integration       # Integration tests only
    poetry run pytest -m "not slow"        # Exclude slow tests
  4. View coverage report:

    # After running tests, open htmlcov/index.html in a browser

Notes

  • The coverage threshold is currently set to 0% to allow the infrastructure to be merged without actual tests. This should be changed to 80% in pyproject.toml once unit tests are added.
  • All validation tests pass, confirming the infrastructure is properly configured.
  • The project uses opencv-python-headless to avoid GUI dependencies in CI/testing environments.
  • Poetry lock file is created and should be committed to ensure reproducible builds.

Next Steps

With this infrastructure in place, developers can now:

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

- Set up Poetry for dependency management with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting and custom markers
- Create test directory structure (unit/integration)
- Add comprehensive pytest fixtures in conftest.py
- Include validation tests to verify setup
- Update .gitignore with Python/testing patterns
- Configure Poetry scripts for test/tests commands
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