segmenter
segmenter copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR sets up a complete testing infrastructure for the Segmenter project using Poetry as the package manager and pytest as the testing framework. The infrastructure is now ready for developers to immediately start writing unit and integration tests.
Changes Made
Package Management
- Poetry Setup: Created
pyproject.tomlwith Poetry configuration - Dependency Migration: Migrated all dependencies from
requirements.txtto Poetry - Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies
Testing Configuration
-
pytest Configuration:
- Configured test discovery patterns
- Set up coverage reporting with 80% threshold
- Added HTML and XML coverage report generation
- Created custom test markers:
unit,integration,slow
-
Coverage Settings:
- Source set to
segmpackage - Excluded test files, scripts, and
__init__.pyfiles from coverage - Configured detailed coverage reports with line precision
- Source set to
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Test Fixtures (in conftest.py)
temp_dir: Temporary directory managementmock_config: Configuration dictionary for testingmock_yaml_config: YAML config file generationmock_model: PyTorch model mockmock_dataset&mock_dataloader: Data loading mocksmock_optimizer&mock_scheduler: Training component mockssample_image&sample_mask: Test tensorsdevice: CUDA/CPU device detectionmock_checkpoint: Checkpoint file generationmock_logger: Logging mockcapture_stdout: Print statement captureenv_vars: Environment variable management
Additional Updates
- Created
segm/__init__.py: Added missing package init file - Updated
.gitignore: Added testing artifacts, Claude settings, and IDE files
How to Use
Install Dependencies
poetry install
Run Tests
Both commands are available:
poetry run test
poetry run tests
Run Specific Test Categories
# Run only unit tests
poetry run pytest -m unit
# Run only integration tests
poetry run pytest -m integration
# Exclude slow tests
poetry run pytest -m "not slow"
Generate Coverage Reports
Coverage reports are automatically generated when running tests:
- Terminal output with missing lines
- HTML report in
htmlcov/directory - XML report as
coverage.xml
Notes
- The project currently has validation tests only. The coverage threshold (80%) will fail until actual unit tests are added.
- All 18 validation tests pass, confirming the infrastructure is properly set up.
- Poetry lock file (
poetry.lock) should be committed to ensure reproducible builds. - The testing infrastructure supports the project's deep learning nature with PyTorch-specific fixtures.
Next Steps
Developers can now:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures in
conftest.pyfor common testing scenarios - Run tests with coverage to ensure code quality