SimMIM
SimMIM 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 SimMIM project using Poetry as the package manager and pytest as the testing framework. The setup provides a ready-to-use testing environment where developers can immediately start writing tests.
Changes Made
Package Management
- Poetry Configuration: Set up Poetry as the package manager with
pyproject.toml - Dependency Migration: Migrated existing dependencies from
requirements.txtto Poetry - Package Mode: Configured as
package-mode = falsefor dependency management only
Testing Dependencies
Added the following development dependencies:
pytest(^7.4.0) - Core testing frameworkpytest-cov(^4.1.0) - Coverage reportingpytest-mock(^3.11.0) - Mocking utilities
Testing Configuration
Configured pytest in pyproject.toml with:
- Test discovery patterns for
test_*.pyand*_test.pyfiles - Coverage reporting for
data,models, and root Python files - Multiple coverage output formats (terminal, HTML, XML)
- Strict markers and configuration
- Custom test markers:
unit,integration,slow
Directory Structure
Created proper testing directory structure:
tests/
├── __init__.py
├── conftest.py
├── test_setup_validation.py
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures
Created comprehensive fixtures in conftest.py:
temp_dir- Temporary directory for test filesmock_config- Mock configuration objectsample_yaml_config- Sample YAML configuration filemock_dataset- Mock dataset objectmock_model- Mock model objectsample_image_tensor- Sample image tensor for testingcaptured_output- Capture stdout/stderr for testingreset_modules- Auto-reset modules between tests
Additional Files
- test.sh: Simple shell script for running tests
- Validation Tests: Created
test_setup_validation.pyto verify the testing infrastructure
Configuration Updates
- Updated
.gitignoreto include.claude/*for Claude-specific settings
How to Use
Install Dependencies
poetry install
Run Tests
You can run tests using any of these methods:
# Using Poetry directly
poetry run pytest
# Using the test script
./test.sh
# Run specific tests
poetry run pytest tests/test_setup_validation.py
# Run with coverage
poetry run pytest --cov
# Run tests by marker
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow
Coverage Reports
Coverage reports are generated in multiple formats:
- Terminal output with missing lines
- HTML report in
htmlcov/directory - XML report as
coverage.xml
Notes
- The coverage threshold requirement has been removed from the initial setup to allow for gradual test development
- The project is configured to exclude test files and
__pycache__from coverage reporting - All validation tests are passing, confirming the infrastructure is properly set up
- The
_pil_interpimport issue fromtimmis handled gracefully in the validation tests
Next Steps
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 track testing progress