Recipes
Recipes copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR sets up a comprehensive testing infrastructure for the project using Poetry as the package manager and pytest as the testing framework. The infrastructure provides a solid foundation for writing and running tests with proper coverage reporting and test organization.
Changes Made
Package Management
- ✅ Added
pyproject.tomlwith Poetry configuration - ✅ Configured project metadata and dependencies
- ✅ Set up development dependencies for testing
Testing Framework
- ✅ Installed pytest as the main testing framework
- ✅ Added pytest-cov for coverage reporting
- ✅ Added pytest-mock for mocking utilities
- ✅ Configured pytest settings in pyproject.toml
Test Configuration
- ✅ Set up coverage reporting with 80% minimum threshold
- ✅ Configured HTML and XML coverage report generation
- ✅ Added test markers:
unit,integration, andslow - ✅ Set up Poetry scripts:
poetry run testandpoetry run tests
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_setup_validation.py # Infrastructure validation tests
├── README.md # Testing documentation
├── unit/ # Unit tests directory
│ └── __init__.py
└── integration/ # Integration tests directory
└── __init__.py
Shared Fixtures (conftest.py)
temp_dir: Temporary directory for test filesmock_model: Mock Lasagne modelmock_layer: Mock Lasagne layersample_input_data: Sample neural network inputsample_labels: Sample labelsmock_config: Configuration dictionarymock_weights_file: Mock weights filemock_dataset: Mock dataset objectmock_theano_function: Mock Theano functiondisable_gpu: Force CPU execution- Session-scoped test directories
Additional Updates
- ✅ Updated .gitignore with testing artifacts and Claude settings
- ✅ Created validation tests to verify the infrastructure
- ✅ Added comprehensive testing documentation
How to Use
-
Install dependencies:
poetry install -
Run all tests:
poetry run test # or poetry run tests -
Run specific test types:
# Unit tests only poetry run pytest -m unit # Integration tests only poetry run pytest -m integration # Exclude slow tests poetry run pytest -m "not slow" -
View coverage report:
- Terminal: Automatically shown after test run
- HTML: Open
htmlcov/index.htmlin browser - XML: Available at
coverage.xml
Validation
The infrastructure has been validated with 13 passing tests that verify:
- pytest is working correctly
- All fixtures are accessible and functional
- Test markers work as expected
- Coverage reporting is properly configured
- Both
poetry run testandpoetry run testscommands work
Notes
- The project dependencies (lasagne, theano, numpy) were inferred from the codebase
- Coverage is currently configured to only track test files for infrastructure validation
- When writing actual tests, update the coverage configuration to track the appropriate source modules
- The poetry.lock file should be committed to ensure reproducible builds