awesome-interpretable-machine-learning
awesome-interpretable-machine-learning copied to clipboard
feat: set up Python testing infrastructure with Poetry and pytest
Set Up Python Testing Infrastructure
Summary
This PR establishes a complete testing infrastructure for the ML Interpretability Papers project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Initialized Poetry as the package manager with
pyproject.tomlconfiguration - Added project metadata and package configuration for the
sbinmodule
Testing Dependencies
Added the following development dependencies:
- pytest (^8.0.0) - Core testing framework
- pytest-cov (^5.0.0) - Coverage reporting plugin
- pytest-mock (^3.14.0) - Mocking utilities
Testing Configuration
- Configured pytest in
pyproject.tomlwith:- Test discovery patterns for
test_*.pyand*_test.pyfiles - Custom markers:
unit,integration, andslow - Strict mode for markers and configuration
- Test discovery patterns for
- Added
.coveragercfor detailed coverage configuration:- 80% coverage threshold (commented out for initial setup)
- HTML and XML report generation
- Exclusion patterns for non-testable code
Directory Structure
Created organized testing structure:
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Fixtures and Configuration
Added comprehensive fixtures in conftest.py:
temp_dir- Temporary directory for testingsample_cache_data- Sample data for cache testingsample_cache_file- Test cache file creationsample_readme_template- Test template filemock_http_response- HTTP response mocking helpermock_env_vars- Environment variable managementisolated_filesystem- Isolated test environment
Development Commands
Configured Poetry scripts for consistent test execution:
poetry run test- Run all testspoetry run tests- Alternative command (both work)
Additional Setup
- Updated
.gitignorewith comprehensive Python, testing, and Claude-specific entries - Added
sbin/__init__.pyto make it a proper Python package - Created validation tests to verify the infrastructure works correctly
How to Use
-
Install dependencies:
poetry install -
Run tests:
# Run all tests poetry run test # Run with coverage poetry run pytest --cov=sbin --cov-report=html # Run specific test markers poetry run pytest -m unit poetry run pytest -m integration -
Write new tests:
- Unit tests go in
tests/unit/ - Integration tests go in
tests/integration/ - Use fixtures from
conftest.pyfor common test needs - Mark tests appropriately with
@pytest.mark.unit, etc.
- Unit tests go in
Notes
- The coverage threshold is currently commented out in
.coveragercsince no actual code tests exist yet - The validation tests confirm that all testing infrastructure is properly installed and configured
- Poetry lock file is tracked in git for reproducible environments
- All pytest options and plugins are available for use