Mask-RCNN
Mask-RCNN copied to clipboard
feat: Add comprehensive testing infrastructure with Poetry
Add Testing Infrastructure for Mask R-CNN PyTorch
Summary
This PR establishes a comprehensive testing infrastructure for the Mask R-CNN PyTorch project using Poetry for dependency management and pytest as the testing framework. The setup provides a ready-to-use environment where developers can immediately start writing and running tests.
Changes Made
Package Management
- Poetry Configuration: Created
pyproject.tomlwith Poetry as the package manager - Dependency Migration: Migrated existing dependencies from the project into Poetry format
- Development Dependencies: Added pytest (^7.4.0), pytest-cov (^4.1.0), pytest-mock (^3.11.1)
- Additional Tools: Included black, isort, flake8, and mypy for code quality
Testing Configuration
- pytest Settings:
- Configured test discovery patterns
- Set 80% coverage threshold
- Added strict markers and configuration
- Enabled verbose output and colored reports
- Coverage Configuration:
- HTML reports in
htmlcov/ - XML reports for CI integration
- Excluded test files, migrations, and virtual environments from coverage
- HTML reports in
- Test Markers:
@pytest.mark.unitfor unit tests@pytest.mark.integrationfor integration tests@pytest.mark.slowfor slow-running tests
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures (minimal version)
├── conftest_full.py.bak # Full fixtures requiring all dependencies
├── README.md # Testing documentation
├── unit/
│ └── __init__.py
├── integration/
│ └── __init__.py
└── test_basic_infrastructure.py # Validation tests
Test Fixtures
Created comprehensive fixtures in conftest.py:
temp_dir: Temporary directory creationmock_config: Mock Mask R-CNN configurationcapture_stdout: Stdout capture for testing printsmock_file_system: Mock directory structureenvironment_variables: Test environment setup
Additional fixtures in conftest_full.py.bak (requires full dependencies):
- Image and tensor fixtures
- Mock models and datasets
- GPU/device detection
- Sample batch data
Poetry Scripts
Added convenient test commands:
poetry run test # Run all tests
poetry run tests # Alternative command
Other Updates
.gitignore: Updated with testing artifacts, coverage files, and.claude/*- Validation Tests: Created tests to verify the infrastructure works correctly
- Documentation: Added comprehensive README in the tests directory
How to Use
-
Install dependencies:
poetry install --with dev -
Run tests:
poetry run test # or with specific options poetry run test -v -m unit --no-cov -
Generate coverage reports:
poetry run test --cov-report=html # Open htmlcov/index.html in browser
Notes
- The current
conftest.pyis a minimal version that works without all project dependencies - Once all dependencies are installed, developers can replace it with
conftest_full.py.bakfor additional fixtures - Poetry lock file is not committed as per
.gitignoreconfiguration - All pytest options are available through the Poetry scripts
Testing the Setup
The PR includes test_basic_infrastructure.py which validates:
- All testing tools are properly installed
- Fixtures work correctly
- Test markers function as expected
- Poetry commands are configured
- Coverage settings are applied
All validation tests pass successfully, confirming the infrastructure is ready for use.