PMG-Progressive-Multi-Granularity-Training
PMG-Progressive-Multi-Granularity-Training copied to clipboard
feat: Add complete Python testing infrastructure with Poetry
Add Complete Python Testing Infrastructure
Summary
This PR sets up a comprehensive testing infrastructure for the ResNet project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and maintaining tests with proper coverage reporting and test organization.
Changes Made
Package Management
- Poetry Setup: Created
pyproject.tomlwith Poetry configuration as the project's package manager - Dependencies: Added core dependencies (torch, torchvision, pillow, numpy) and development dependencies (pytest, pytest-cov, pytest-mock)
- Script Commands: Configured both
poetry run testandpoetry run testscommands for running tests
Testing Configuration
-
pytest Configuration:
- Set up test discovery patterns for
test_*.pyand*_test.pyfiles - Configured strict markers and error handling
- Added custom markers:
unit,integration, andslowfor test categorization
- Set up test discovery patterns for
-
Coverage Configuration:
- Set 80% coverage threshold
- Configured HTML, XML, and terminal coverage reports
- Excluded test files, cache directories, and virtual environments from coverage
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── unit/ # Unit tests directory
│ └── __init__.py
├── integration/ # Integration tests directory
│ └── __init__.py
└── test_setup_validation.py # Validation tests
Fixtures and Testing Utilities
Created comprehensive fixtures in conftest.py:
temp_dir: Temporary directory managementsample_image_path: Mock image file creationmock_model_config: Model configuration for testingmock_dataset_config: Dataset configuration for testingdevice: PyTorch device selectionsample_tensor&sample_batch: Test data generationreset_random_seeds: Reproducibility fixturemock_checkpoint: Model checkpoint creationenvironment_setup: Environment variable management
Additional Files
.gitignore: Comprehensive Python gitignore with testing artifacts, IDE files, and project-specific patternsCLAUDE.md: Documentation for Claude AI with testing commands and project structure- Validation Tests: Created tests to verify the infrastructure setup works correctly
How to Use
-
Install dependencies:
poetry install -
Run tests:
# Run all tests poetry run test # Run with coverage poetry run pytest --cov=. --cov-report=term --cov-report=html # Run specific test categories poetry run pytest -m unit poetry run pytest -m integration poetry run pytest -m "not slow" -
View coverage reports:
- Terminal: Shown after test run
- HTML: Open
htmlcov/index.htmlin browser - XML: Available at
coverage.xmlfor CI integration
Next Steps
With this infrastructure in place, developers can now:
- Write unit tests for individual functions and classes
- Create integration tests for end-to-end workflows
- Add more specialized fixtures as needed
- Integrate with CI/CD pipelines using the coverage reports
Notes
- Poetry was chosen as the package manager since no existing package manager was detected
- The 80% coverage threshold is configured but can be adjusted in
pyproject.toml - All testing dependencies are properly isolated as development dependencies
- The validation test suite confirms that all components are working correctly