QuickDraw
QuickDraw copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR sets up a comprehensive testing infrastructure for the QuickDraw Python project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Configuration: Added
pyproject.tomlwith Poetry configuration for dependency management - Package Mode: Set to false since this is an application, not a library
- Python Version: Set to Python 3.7+ for compatibility with modern testing tools
Testing Dependencies
Added the following development dependencies:
pytest(^7.4.0): Core testing frameworkpytest-cov(^4.1.0): Coverage reporting pluginpytest-mock(^3.11.1): Mocking utilities
Testing Configuration
Configured comprehensive pytest settings in pyproject.toml:
- Test Discovery: Configured to find tests in the
tests/directory - Coverage Settings:
- Source directories:
src/,train.py,draw.py, and all app files - Coverage reports: Terminal, HTML (
htmlcov/), and XML (coverage.xml) - Coverage threshold: Currently set to 0% (should be increased as tests are added)
- Source directories:
- Test Markers: Added
unit,integration, andslowmarkers for test categorization - Output Options: Verbose output with short tracebacks
Directory Structure
Created organized testing structure:
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
Added comprehensive fixtures for common testing needs:
temp_dir: Temporary directory creationsample_image_array: Mock image datasample_batch: PyTorch tensor batchesmock_config: Configuration dictionariesmock_dataset_path: Mock dataset creationdevice: PyTorch device selectionmock_tensorboard_writer: TensorBoard mockingmock_cv2: OpenCV mocking- Random seed resetting for reproducibility
Additional Configuration
- Updated .gitignore: Added entries for testing artifacts, coverage reports, and Claude settings
- Poetry Scripts: Both
poetry run testandpoetry run testscommands are available
How to Use
Install Dependencies
poetry install --with dev
Run Tests
# Run all tests
poetry run pytest
# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
# Run specific test file
poetry run pytest tests/test_setup_validation.py
View Coverage Reports
- Terminal: Coverage is shown automatically after test runs
- HTML: Open
htmlcov/index.htmlin a browser - XML: Available at
coverage.xmlfor CI/CD integration
Validation
The setup includes a comprehensive validation test (test_setup_validation.py) that verifies:
- All testing dependencies are properly installed
- Project structure is correct
- All fixtures are working properly
- Test markers are configured
- Mocking capabilities are functional
All validation tests are passing ✅
Next Steps
- Developers can now start writing unit tests in
tests/unit/ - Integration tests can be added to
tests/integration/ - Coverage threshold should be gradually increased as tests are added
- Consider adding pre-commit hooks for running tests
Notes
- The project uses Poetry's package-mode=false since it's an application
- Coverage warnings about unimported modules are expected until actual tests are written
- The testing infrastructure supports all major testing patterns (mocking, fixtures, markers, coverage)