feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR sets up a complete testing infrastructure for the VAmPI project using Poetry for dependency management and pytest as the testing framework. The setup provides a foundation for writing unit and integration tests with proper coverage reporting.
Changes Made
Package Management
- Migrated from
requirements.txtto Poetry (pyproject.toml) - Configured Poetry with
package-mode = falsefor non-distributable projects - Created
poetry.lockfile to ensure reproducible builds
Testing Dependencies
Added the following development dependencies:
- pytest (^7.4.0) - Main testing framework
- pytest-cov (^4.1.0) - Coverage reporting integration
- pytest-mock (^3.11.0) - Mocking utilities for tests
Testing Configuration
Configured comprehensive testing settings in pyproject.toml:
- Test discovery: Configured paths and naming patterns
- Coverage settings:
- 80% coverage threshold requirement
- HTML and XML report generation
- Branch coverage enabled
- Exclusion patterns for non-testable code
- Custom markers:
unit,integration, andslowfor test categorization - Strict mode: Enabled strict markers and configuration
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_infrastructure_only.py # Validation tests
├── test_setup_validation.py # Additional validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures
Created reusable fixtures in conftest.py:
temp_dir- Temporary directory for test filesmock_config- Mock Flask configurationsample_user_data- Test user datasample_book_data- Test book datacapture_logs- Log capturing utility
Additional Updates
- Updated
.gitignoreto exclude testing artifacts and Claude settings - Updated
CLAUDE.mdwith testing commands documentation
Running Tests
Basic Commands
# Install dependencies
poetry install
# Run all tests
poetry run pytest
# Run with verbose output
poetry run pytest -v
# Run specific test file
poetry run pytest tests/test_infrastructure_only.py
# Run tests by marker
poetry run pytest -m unit
poetry run pytest -m integration
Coverage Commands
# Run with coverage report
poetry run pytest --cov
# Generate HTML coverage report
poetry run pytest --cov-report=html
# Skip coverage for validation
poetry run pytest --no-cov
Notes
-
Circular Import Issue: The application has circular imports between
app.py,config.py, and model files. Tests that import the app will fail until this is resolved. The infrastructure validation tests work without importing the app. -
Poetry Scripts: The
poetry run testandpoetry run testscommands are configured but show warnings due to the package-mode setting. Usepoetry run pytestdirectly for now. -
Coverage Threshold: The 80% coverage requirement is configured but will fail until actual unit tests are written for the application code.
Next Steps
- Resolve circular import issues in the application code
- Write unit tests for API views and models
- Write integration tests for API endpoints
- Set up CI/CD pipeline to run tests automatically