PythonSIFT
PythonSIFT copied to clipboard
feat: add comprehensive Python testing infrastructure with Poetry
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.tomlwith 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
- Source directory set to
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 filessample_image: Color test image (100x100)grayscale_image: Grayscale test imagesample_keypoints: OpenCV KeyPoint objectssample_descriptors: Mock SIFT descriptorsmock_config: Configuration dictionarytest_image_path: Saved test image pathcapture_stdout: Stdout capture utilitymock_sift_detector: Mocked SIFT detector
5. Poetry Scripts
Added convenient test commands:
poetry run test- Run all tests with coveragepoetry run tests- Alternative command (both work)
6. Additional Changes
- Created
.gitignorewith comprehensive Python patterns - Added validation tests to verify the infrastructure works
- Used opencv-python-headless to avoid GUI dependencies in tests
How to Use
-
Install dependencies:
poetry install -
Run tests:
poetry run test # or poetry run tests # or poetry run pytest # with custom options -
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 -
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.tomlonce 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:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common testing needs
- Run tests with coverage to ensure code quality