cookbook-2nd
cookbook-2nd 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 IPython Cookbook project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Configuration: Created
pyproject.tomlwith Poetry configuration- Set up project metadata
- Configured package-mode as false (dependency management only)
- Added test/dev dependencies: pytest, pytest-cov, pytest-mock
Testing Configuration
-
pytest Configuration in
pyproject.toml:- Test discovery patterns for
test_*.pyand*_test.pyfiles - Coverage settings with 80% threshold
- HTML and XML coverage report generation
- Custom markers:
unit,integration,slow - Strict marker enforcement
- Test discovery patterns for
-
Coverage Configuration:
- Source includes all project files
- Excludes test files, virtual environments, and build artifacts
- Precision set to 2 decimal places
- Shows missing lines in coverage reports
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_infrastructure.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
temp_dir: Creates temporary directories for testingtemp_file: Creates temporary files with contentmock_config: Provides mock configuration dictionariessample_data: Sample data structures for testingmock_notebook_data: Mock Jupyter notebook structuresreset_environment: Auto-resets environment variablescapture_logs: Log capture configurationmock_http_response: Factory for creating mock HTTP responses
Development Commands
Both commands are available for running tests:
poetry run pytest- Direct pytest execution- Standard pytest options are available (e.g.,
-v,-k,--runslow)
.gitignore Updates
Added comprehensive entries for:
- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/) - Python artifacts (
__pycache__/,*.pyc,*.pyo) - Virtual environments
- Build artifacts
- IDE files
- Claude settings (
.claude/*)
How to Use
-
Install dependencies:
poetry install -
Run all tests:
poetry run pytest -
Run tests with coverage:
poetry run pytest --cov -
Run specific test markers:
poetry run pytest -m unit # Run only unit tests poetry run pytest -m integration # Run only integration tests poetry run pytest --runslow # Include slow tests -
View coverage report:
- HTML report: Open
htmlcov/index.htmlin a browser - Terminal report: Included by default when running tests
- HTML report: Open
Notes
- The infrastructure is ready for immediate use - developers can start writing tests in the
tests/unit/ortests/integration/directories - Coverage threshold is set to 80% but will only apply once actual code is added to the project
- All validation tests pass, confirming the infrastructure is properly configured
- Poetry lock file is tracked in git for reproducible builds