Verbi
Verbi copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Add Comprehensive Python Testing Infrastructure
Summary
This PR sets up a complete testing infrastructure for the JARVIS Voice Assistant project using Poetry as the package manager and pytest as the testing framework. The infrastructure provides everything needed for developers to immediately start writing and running tests.
Changes Made
Package Management
- Poetry Configuration: Created
pyproject.tomlwith full Poetry setup - Dependency Migration: Migrated all dependencies from
requirements.txtandsetup.pyto Poetry - Development Dependencies: Added pytest (8.0+), pytest-cov (5.0+), and pytest-mock (3.14+)
Testing Configuration
-
pytest Configuration:
- Test discovery patterns for
test_*.pyand*_test.pyfiles - Strict markers and configuration enforcement
- Custom markers:
unit,integration,slow - Verbose output with detailed failure information
- Test discovery patterns for
-
Coverage Configuration:
- 80% coverage threshold (when coverage is enabled)
- Multiple report formats: terminal, HTML (
htmlcov/), XML (coverage.xml) - Intelligent exclusions for non-testable code patterns
- Skip covered lines in terminal output for clarity
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 test isolationtemp_file: Creates temporary files with contentmock_config: Provides mock configuration dictionariesmock_env_vars: Sets up mock environment variablesmock_api_response: Mock API response structuresmock_audio_data: Mock audio data for testingmock_llm_client,mock_tts_client,mock_stt_client: Mock service clientscapture_logs: Captures log messages during testsmock_file_system: Creates mock file system structuresperformance_timer: Measures test execution time
Running Tests
Basic Commands
# Run all tests
poetry run test
# Alternative command (both work)
poetry run tests
# Run tests with coverage
poetry run pytest --cov
# Run specific test file
poetry run pytest tests/test_infrastructure.py
# Run tests by marker
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
Using the Test Script
# Run tests without coverage
./scripts/test.sh
# Run tests with coverage enforcement
./scripts/test.sh coverage
# Pass additional pytest arguments
./scripts/test.sh -v -k test_name
Validation
The infrastructure has been validated with 17 passing tests that verify:
- All testing dependencies are properly installed
- Fixtures work correctly and provide expected functionality
- Directory structure is properly created
- Configuration files are correctly set up
- Test markers can be applied and used
Notes
- PyAudio Dependency: Temporarily removed from dependencies due to missing system libraries (portaudio). This can be re-added once system dependencies are installed.
- Coverage Source: Currently configured to only measure test coverage. Update
[tool.coverage.run]source to include your application code when ready. - poetry.lock: This file is not gitignored and should be committed to ensure reproducible builds.
Next Steps
-
Install system dependencies for PyAudio if audio functionality is needed:
# Ubuntu/Debian sudo apt-get install portaudio19-dev # macOS brew install portaudio -
Update coverage configuration to include source code:
[tool.coverage.run] source = ["your_package_name"] -
Start writing tests in the
tests/unit/andtests/integration/directories -
Consider adding pre-commit hooks to run tests automatically
Testing the Setup
To verify everything is working correctly:
# Install dependencies
poetry install
# Run validation tests
poetry run pytest tests/test_infrastructure.py -v
# Check that both test commands work
poetry run test --version
poetry run tests --version