SoftTeacher
SoftTeacher 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 SSOD (Semi-Supervised Object Detection) Python project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Configuration: Created
pyproject.tomlwith Poetry as the package manager - Dependency Migration: Migrated existing dependencies from
requirements.txtto Poetry - Development Dependencies: Added testing tools as development dependencies
Testing Framework
- pytest: Main testing framework with comprehensive configuration
- pytest-cov: Coverage reporting with 80% threshold requirement
- pytest-mock: Mocking utilities for unit tests
Project Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── unit/ # Unit tests
│ └── __init__.py
├── integration/ # Integration tests
│ └── __init__.py
└── test_infrastructure_validation.py # Validation tests
Configuration
pytest Configuration (in pyproject.toml)
- Minimum version requirement: 7.0
- Automatic test discovery patterns
- Coverage reporting (terminal, HTML, XML)
- 80% coverage threshold
- Custom test markers:
unit,integration,slow - Strict mode enabled for better error detection
Coverage Configuration
- Source:
ssodpackage - Branch coverage enabled
- Exclusions for test files,
__init__.py, and common patterns - HTML report output to
htmlcov/ - XML report for CI integration
Testing Fixtures (conftest.py)
Created comprehensive fixtures for common testing needs:
temp_dir/temp_file: Temporary file system resourcesmock_config: Sample configuration dictionarymock_model/mock_dataset/mock_dataloader: PyTorch mockssample_json_file: JSON test datamock_wandb: Weights & Biases mockingmock_torch_save/mock_torch_load: PyTorch I/O mockingdevice/sample_tensor/sample_batch: PyTorch helpersreset_torch_seed: Reproducible testscapture_logs: Log output testingmock_os_environ: Environment variable testing
Additional Files
- CLAUDE.md: Documentation for common testing commands
- .gitignore: Updated with testing artifacts and Claude settings
How to Use
Install Dependencies
poetry install
Run Tests
# Run all tests
poetry run test
# or
poetry run tests
# Run with coverage
poetry run pytest --cov
# Run specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
# Run specific file
poetry run pytest tests/test_file.py
View Coverage Report
After running tests with coverage, open htmlcov/index.html in a browser to view the detailed coverage report.
Validation
The infrastructure includes validation tests (test_infrastructure_validation.py) that verify:
- All testing dependencies are properly installed
- Project structure is correctly set up
- Fixtures are working as expected
- Custom markers are configured
- Coverage reporting functions properly
Notes
- The project uses Poetry for dependency management, which provides better dependency resolution and lock file support compared to pip
- Coverage threshold is set to 80% to encourage comprehensive testing
- The infrastructure is ready for immediate test development - developers can start writing tests in the
unit/orintegration/directories - All test-related artifacts (.pytest_cache, coverage reports, etc.) are properly gitignored